GetFEM  5.4.3
getfem_mat_elem.h
Go to the documentation of this file.
1 /* -*- c++ -*- (enables emacs c++ mode) */
2 /*===========================================================================
3 
4  Copyright (C) 2000-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_mat_elem.h
33  @author Yves Renard <Yves.Renard@insa-lyon.fr>
34  @date December 21, 2000.
35  @brief elementary computations (used by the generic assembly).
36 
37  This is the kernel of getfem low-level generic assembly.
38 */
39 
40 #ifndef GETFEM_MAT_ELEM_H__
41 #define GETFEM_MAT_ELEM_H__
42 
43 #include "getfem_mat_elem_type.h"
44 #include "getfem_fem.h"
45 
46 namespace getfem {
47  /** @internal (optional) callback to be called for each point of the
48  integration (i.e. only with approximate integrations). It is
49  used by getfem_assembling_tensors to perform reductions before
50  integration.
51  */
52  struct mat_elem_integration_callback {
53  /* this vector is filled by mat_elem, it contains a pointer to each tensor
54  build from a term in the mat_elem_type (base functions, gradients,
55  nonlinear terms etc)
56  */
57  std::vector<const bgeot::base_tensor*> eltm;
58  /** executes the callback
59 
60  @param t the destination tensor
61 
62  @param first indicates if this is the first integration point
63  (in that case, t should be set to the correct size and filled
64  with zeros)
65 
66  @param c the current coefficient (contains the norm of
67  Jacobian and the integration weight)
68  */
69  virtual void exec(bgeot::base_tensor &t, bool first, scalar_type c) = 0;
70  virtual ~mat_elem_integration_callback() {}
71  };
72 
73  /** @internal
74  this class (whose instances are returned by the mat_elem
75  function, see below) holds all computations of elementary
76  integrals over convexes or faces of convexes.
77  */
78  class mat_elem_computation : virtual public dal::static_stored_object {
79  protected :
80 
82  pmat_elem_type pme;
83  mutable base_matrix pa;
84 
85  public :
86 
87  virtual void compute(base_tensor &t, const base_matrix &a,
88  size_type elt,
89  mat_elem_integration_callback *icb = 0) const = 0;
90  virtual void compute_on_face(base_tensor &t, const base_matrix &a,
91  short_type f, size_type elt,
92  mat_elem_integration_callback *icb = 0)
93  const = 0;
94  /**
95  perform the integration on the volume of a convex.
96  @param t the destination tensor
97  @param a the list of vertices of the convex
98  @param elt the convex number
99  @param icb an optional callback which will be called for each
100  integration point
101  */
102  template <class CONT> void
103  gen_compute(base_tensor &t, const CONT &a, size_type elt,
104  mat_elem_integration_callback *icb = 0) const {
105  bgeot::vectors_to_base_matrix(pa, a);
106  compute(t, pa, elt, icb);
107  }
108  /**
109  perform the integration on a face of the convex
110  */
111  template <class CONT> void
112  gen_compute_on_face(base_tensor &t,
113  const CONT &a, short_type f, size_type elt,
114  mat_elem_integration_callback *icb = 0) const {
115  bgeot::vectors_to_base_matrix(pa, a);
116  compute_on_face(t, pa, f, elt, icb);
117  }
118 
119  mat_elem_computation()
120  { DAL_STORED_OBJECT_DEBUG_CREATED(this, "Mat elem computation"); }
121  virtual ~mat_elem_computation()
122  { DAL_STORED_OBJECT_DEBUG_DESTROYED(this, "Mat elem computation"); }
123  virtual size_type memsize() const = 0;
124  };
125 
126  typedef std::shared_ptr<const mat_elem_computation>
127  pmat_elem_computation;
128 
129  /**
130  allocate a structure for computation (integration over elements
131  or faces of elements) of elementary tensors. Internally this
132  structure is linked to a "cache" which stores some pre-computed
133  data.
134  */
135  pmat_elem_computation mat_elem(pmat_elem_type pm,
136  pintegration_method pi,
138  bool prefer_comp_on_real_element=false);
139 
140  class mat_elem_pool {
141  std::set<pmat_elem_computation> mat_elems;
142 
143  public :
144  pmat_elem_computation operator()(pmat_elem_type pm,
145  pintegration_method pi,
147  bool prefer_comp_on_real_element=false) {
148  pmat_elem_computation p=mat_elem(pm, pi, pg, prefer_comp_on_real_element);
149  mat_elems.insert(p);
150  return p;
151  }
152  void clear(void) {
153  for (auto it = mat_elems.begin(); it != mat_elems.end(); ++it)
154  del_stored_object(*it, true);
155  mat_elems.clear();
156  }
157  ~mat_elem_pool() { clear(); }
158  };
159 } /* end of namespace getfem. */
160 
161 
162 #endif /* GETFEM_MAT_ELEM_H__ */
base class for static stored objects
Definition of the finite element methods.
Build elementary tensors descriptors, used by generic assembly.
void clear(L &l)
clear (fill with zeros) a vector or matrix.
Definition: gmm_blas.h:59
gmm::uint16_type short_type
used as the common short type integer in the library
Definition: bgeot_config.h:73
size_t size_type
used as the common size type in the library
Definition: bgeot_poly.h:49
std::shared_ptr< const bgeot::geometric_trans > pgeometric_trans
pointer type for a geometric transformation
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.
pmat_elem_computation mat_elem(pmat_elem_type pm, pintegration_method pi, bgeot::pgeometric_trans pg, bool prefer_comp_on_real_element=false)
allocate a structure for computation (integration over elements or faces of elements) of elementary t...