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