GetFEM  5.5
getfem_interpolated_fem.h
Go to the documentation of this file.
1 /* -*- c++ -*- (enables emacs c++ mode) */
2 /*===========================================================================
3 
4  Copyright (C) 2004-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 /**@file getfem_interpolated_fem.h
31  @author Yves Renard <Yves.Renard@insa-lyon.fr>
32  @date October 29, 2004.
33  @brief FEM which interpolates a mesh_fem on a different mesh.
34 
35  To be corrected : dependencies. The mesh fem using this fem will
36  not depend on the mesh fem arguments.
37 */
38 
39 
40 #ifndef GETFEM_INTERPOLATED_FEM_H__
41 #define GETFEM_INTERPOLATED_FEM_H__
42 
43 #include "getfem_fem.h"
44 #include "getfem_mesh_fem.h"
45 #include "getfem_mesh_im.h"
46 #include "bgeot_rtree.h"
47 #include "bgeot_geotrans_inv.h"
48 
49 namespace getfem {
50 
51  // Object representing global transformation. To be derived.
52 
53  struct virtual_interpolated_func {
54  virtual void val(const base_node&, base_node &) const
55  { GMM_ASSERT1(false, "this interpolated_func has no value"); }
56  virtual void grad(const base_node&, base_matrix &) const
57  { GMM_ASSERT1(false, "this interpolated_func has no gradient"); }
58  virtual void hess(const base_node&, base_matrix &) const
59  { GMM_ASSERT1(false, "this interpolated_func has no hessian"); }
60  virtual ~virtual_interpolated_func() {}
61  };
62 
63 
64  typedef const virtual_interpolated_func *pinterpolated_func;
65 
66 
67  struct gausspt_interpolation_data {
68  size_type elt; // convex of the interpolated mesh_fem under the gauss point
69  size_type iflags; // flags & 1 : there is an element or not
70  // flags & 2 : base_val is stored
71  // flags & 4 : grad_val is stored
72  base_node ptref; // coords on reference element of mf1 element
73  base_tensor base_val; // optional storage of the base values
74  base_tensor grad_val; // optional storage of the grad base values
75  std::vector<size_type> local_dof; // correspondence between dof of the
76  // mf1 element and dof of the interpolated element.
77  gausspt_interpolation_data() : elt(size_type(-1)), iflags(size_type(-1)) {}
78  };
79 
80  /** FEM which interpolates a mesh_fem on a different mesh.
81 
82  Note that the memory cost of this method is extremely high!
83  */
85 
86  protected :
87 
88  struct elt_interpolation_data {
90  std::vector<gausspt_interpolation_data> gausspt;
91  std::vector<size_type> inddof;
92  pintegration_method pim; // for DEBUG
93  elt_interpolation_data() : nb_dof(0), pim(0) {}
94  };
95 
96  const mesh_fem &mf; // mf represents the original finite element method
97  // to be interpolated.
98  const mesh_im &mim; // mesh on which mf1 is interpolated. contains
99  // also the integration method.
100  pinterpolated_func pif; // optional transformation
101 
102  bool store_values;
103  dal::bit_vector blocked_dof;
104 
105  // auxiliary variables
106  mutable std::vector<elt_interpolation_data> elements;
107  mutable bgeot::rtree boxtree; // Tree containing the bounding box
108  // of mf1 elements
109  mutable std::map<size_type, std::vector<size_type>> box_to_convexes_map;
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;
146  base_tensor &t, bool = true) const;
148  base_tensor &t, bool = true) const;
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 
Inversion of geometric transformations.
region-tree for window/point search on a set of rectangles.
does the inversion of the geometric transformation for a given convex
Balanced tree of n-dimensional rectangles.
Definition: bgeot_rtree.h:97
Deal with interdependencies of objects.
structure passed as the argument of fem interpolation functions.
Definition: getfem_fem.h:749
FEM which interpolates a mesh_fem on a different mesh.
void real_grad_base_value(const fem_interpolation_context &c, base_tensor &t, bool=true) const
Give the gradient of all components of the base functions at the current point of the fem_interpolati...
void real_base_value(const fem_interpolation_context &c, base_tensor &t, bool=true) const
Give the value of all components of the base functions at the current point of the fem_interpolation_...
void grad_base_value(const base_node &, base_tensor &) const
Give the value of all gradients (on ref.
virtual size_type nb_dof(size_type cv) const
Number of degrees of freedom.
virtual void update_from_context(void) const
this function has to be defined and should update the object when the context is modified.
virtual const bgeot::convex< base_node > & node_convex(size_type cv) const
Gives the convex representing the nodes on the reference element.
void hess_base_value(const base_node &, base_tensor &) const
Give the value of all hessians (on ref.
void base_value(const base_node &, base_tensor &) const
Give the value of all components of the base functions at the point x of the reference element.
void gauss_pts_stats(unsigned &ming, unsigned &maxg, scalar_type &meang) const
return the min/max/mean number of gauss points in the convexes of the interpolated mesh_fem
void real_hess_base_value(const fem_interpolation_context &, base_tensor &, bool=true) const
Give the hessian of all components of the base functions at the current point of the fem_interpolatio...
dal::bit_vector interpolated_convexes() const
return the list of convexes of the interpolated mesh_fem which contain at least one gauss point (shou...
virtual bgeot::pconvex_ref ref_convex(size_type cv) const
Return the convex of the reference element.
Describe a finite element method linked to a mesh.
Describe an integration method linked to a mesh.
Base class for finite element description.
Definition: getfem_fem.h:255
Definition of the finite element methods.
Define the getfem::mesh_fem class.
Define the getfem::mesh_im class (integration of getfem::mesh_fem).
std::shared_ptr< const getfem::virtual_fem > pfem
type of pointer on a fem description
Definition: getfem_fem.h:243
size_t size_type
used as the common size type in the library
Definition: bgeot_poly.h:48
void del_stored_object(const pstatic_stored_object &o, bool ignore_unstored)
Delete an object and the object which depend on it.
GEneric Tool for Finite Element Methods.
void del_interpolated_fem(const pfem &pf)
release an interpolated fem
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.