GetFEM++  5.3
getfem_generic_assembly_compile_and_exec.h
1 /*===========================================================================
2 
3  Copyright (C) 2013-2018 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  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_generic_assembly_tree.h
32  @author Yves Renard <Yves.Renard@insa-lyon.fr>
33  @date November 18, 2013.
34  @brief Compilation and execution operations. */
35 
36 
37 #ifndef GETFEM_GENERIC_ASSEMBLY_COMP_EXEC_H__
38 #define GETFEM_GENERIC_ASSEMBLY_COMP_EXEC_H__
39 
41 
42 namespace getfem {
43 
44  class ga_if_hierarchy : public std::vector<size_type> {
45 
46  public:
47  void increment() { (back())++; }
48  void child_of(const ga_if_hierarchy &gih)
49  { *this = gih; push_back(0); }
50  bool is_compatible(const std::list<ga_if_hierarchy> &gihl) {
51 
52  std::list<ga_if_hierarchy>::const_iterator it = gihl.begin();
53  for (; it != gihl.end(); ++it) {
54  if (it->size() <= size()) {
55  bool ok = true;
56  for (size_type i = 0; i+1 < it->size(); ++i)
57  if ((*it)[i] != (*this)[i]) { ok = false; break; }
58  if (it->back() > (*this)[it->size()-1]) { ok = false; break; }
59  if (ok) return true;
60  }
61  }
62  return false;
63  }
64 
65  ga_if_hierarchy() : std::vector<size_type>(1) { (*this)[0] = 0; }
66  };
67 
68 
69  struct ga_instruction {
70  virtual int exec() = 0;
71  virtual ~ga_instruction() {};
72  };
73 
74  typedef std::shared_ptr<ga_instruction> pga_instruction;
75  typedef std::vector<pga_instruction> ga_instruction_list;
76 
77 
78  struct gauss_pt_corresp { // For neighbour interpolation transformation
79  bgeot::pgeometric_trans pgt1, pgt2;
80  papprox_integration pai;
81  std::vector<size_type> nodes;
82  };
83 
84  bool operator <(const gauss_pt_corresp &gpc1,
85  const gauss_pt_corresp &gpc2);
86 
87  struct ga_instruction_set {
88 
89  papprox_integration pai; // Current approximation method
90  fem_interpolation_context ctx; // Current fem interpolation context.
91  base_small_vector Normal; // Outward unit normal vector to the
92  // boundary in case of boundary integration
93  scalar_type elt_size; // Estimate of the diameter of the element
94  // if needed.
95  bool need_elt_size;
96  scalar_type coeff; // Coefficient for the Gauss point
97  size_type nbpt, ipt; // Number and index of Gauss point
99  fem_precomp_pool fp_pool;
100  std::map<gauss_pt_corresp, bgeot::pstored_point_tab> neighbour_corresp;
101 
102  struct region_mim : std::pair<const mesh_im *, const mesh_region *> {
103  const mesh_im* mim() const { return this->first; }
104  const mesh_region* region() const { return this->second; }
105  region_mim(const mesh_im *mim_, const mesh_region *region_) :
106  std::pair<const mesh_im *, const mesh_region *>(mim_, region_) {}
107  };
108 
109  std::map<std::string, const base_vector *> extended_vars;
110  std::map<std::string, base_vector> really_extended_vars;
111  std::map<std::string, gmm::sub_interval> var_intervals;
112  size_type nb_dof, max_dof;
113 
114  struct variable_group_info {
115  const mesh_fem *mf;
116  gmm::sub_interval Ir, In;
117  scalar_type alpha;
118  const base_vector *U;
119  const std::string *varname;
120  variable_group_info() : mf(0), U(0), varname(0) {}
121  };
122 
123  struct interpolate_info {
124  size_type pt_type;
125  bool has_ctx;
126  const mesh *m;
127  fem_interpolation_context ctx;
128  base_node pt_y;
129  base_small_vector Normal;
130  base_matrix G;
131  std::map<std::string, variable_group_info> groups_info;
132  std::map<var_trans_pair, base_tensor> derivatives;
133  std::map<const mesh_fem *, pfem_precomp> pfps;
134  };
135 
136  struct elementary_trans_info {
137  base_matrix M;
138  const mesh_fem *mf;
139  size_type icv;
140  };
141 
142  std::set<std::string> transformations;
143 
144  struct region_mim_instructions {
145 
146  const mesh *m;
147  const mesh_im *im;
148  ga_if_hierarchy current_hierarchy;
149  std::map<std::string, base_vector> local_dofs;
150  std::map<const mesh_fem *, pfem_precomp> pfps;
151  std::map<const mesh_fem *, base_tensor> base;
152  std::map<const mesh_fem *, std::list<ga_if_hierarchy>> base_hierarchy;
153  std::map<const mesh_fem *, base_tensor> grad;
154  std::map<const mesh_fem *, std::list<ga_if_hierarchy>> grad_hierarchy;
155  std::map<const mesh_fem *, base_tensor> hess;
156  std::map<const mesh_fem *, std::list<ga_if_hierarchy>> hess_hierarchy;
157 
158  std::map<const mesh_fem *, base_tensor>
159  xfem_plus_base, xfem_plus_grad, xfem_plus_hess,
160  xfem_minus_base, xfem_minus_grad, xfem_minus_hess;
161  std::map<const mesh_fem *, std::list<ga_if_hierarchy>>
162  xfem_plus_base_hierarchy, xfem_plus_grad_hierarchy,
163  xfem_plus_hess_hierarchy, xfem_minus_base_hierarchy,
164  xfem_minus_grad_hierarchy, xfem_minus_hess_hierarchy;
165 
166  std::map<std::string, std::set<std::string>> transformations;
167  std::set<std::string> transformations_der;
168  std::map<std::string, interpolate_info> interpolate_infos;
169  std::map<std::string, elementary_trans_info> elementary_trans_infos;
170 
171  // Instructions being executed at the first Gauss point after
172  // a change of integration method only.
173  ga_instruction_list begin_instructions;
174  // Instructions executed once per element
175  ga_instruction_list elt_instructions;
176  // Instructions executed on each integration/interpolation point
177  ga_instruction_list instructions;
178  std::map<scalar_type, std::list<pga_tree_node> > node_list;
179 
180  region_mim_instructions(): m(0), im(0) {}
181  };
182 
183  std::list<ga_tree> trees; // The trees are stored mainly because they
184  // contain the intermediary tensors.
185  std::list<ga_tree> interpolation_trees;
186 
187  typedef std::map<region_mim, region_mim_instructions> instructions_set;
188 
189  instructions_set whole_instructions;
190 
191  ga_instruction_set() { max_dof = nb_dof = 0; need_elt_size = false; ipt=0; }
192  };
193 
194 
195  void ga_exec(ga_instruction_set &gis, ga_workspace &workspace);
196  void ga_function_exec(ga_instruction_set &gis);
197  void ga_compile(ga_workspace &workspace, ga_instruction_set &gis,
198  size_type order);
199  void ga_compile_function(ga_workspace &workspace,
200  ga_instruction_set &gis, bool scalar);
201  void ga_compile_interpolation(ga_workspace &workspace,
202  ga_instruction_set &gis);
203  void ga_interpolation_exec(ga_instruction_set &gis,
204  ga_workspace &workspace,
205  ga_interpolation_context &gic);
206  void ga_interpolation_single_point_exec
207  (ga_instruction_set &gis, ga_workspace &workspace,
208  const fem_interpolation_context &ctx_x, const base_small_vector &Normal,
209  const mesh &interp_mesh);
210 
211 } /* end of namespace */
212 
213 
214 #endif /* GETFEM_GENERIC_ASSEMBLY_COMP_EXEC_H__ */
The object geotrans_precomp_pool Allow to allocate a certain number of geotrans_precomp and automatic...
Semantic analysis of assembly trees and semantic manipulations.
size_t size_type
used as the common size type in the library
Definition: bgeot_poly.h:49
GEneric Tool for Finite Element Methods.
size_type alpha(short_type n, short_type d)
Return the value of which is the number of monomials of a polynomial of variables and degree ...
Definition: bgeot_poly.cc:46
std::shared_ptr< const bgeot::geometric_trans > pgeometric_trans
pointer type for a geometric transformation