GetFEM  5.4.2
getfem_generic_assembly_compile_and_exec.h
1 /*===========================================================================
2 
3  Copyright (C) 2013-2020 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) { *this = gih; push_back(0); }
49  bool is_compatible(const std::list<ga_if_hierarchy> &gihl) {
50  for (const auto &gih : gihl) {
51  if (gih.size() <= size()) {
52  bool ok = true;
53  for (size_type i = 0; i+1 < gih.size(); ++i)
54  if (gih[i] != (*this)[i]) { ok = false; break; }
55  if (gih.back() > (*this)[gih.size()-1]) { ok = false; break; }
56  if (ok) return true;
57  }
58  }
59  return false;
60  }
61 
62  ga_if_hierarchy() : std::vector<size_type>(1) { (*this)[0] = 0; }
63  };
64 
65 
66  struct ga_instruction {
67  virtual int exec() = 0;
68  virtual ~ga_instruction() {};
69  };
70 
71  typedef std::shared_ptr<ga_instruction> pga_instruction;
72 
73  struct gauss_pt_corresp { // For neighbor interpolation transformation
74  bgeot::pgeometric_trans pgt1, pgt2;
75  papprox_integration pai;
76  std::vector<size_type> nodes;
77  };
78 
79  bool operator <(const gauss_pt_corresp &gpc1,
80  const gauss_pt_corresp &gpc2);
81 
82  struct ga_instruction_set {
83 
84  papprox_integration pai; // Current approximation method
85  fem_interpolation_context ctx; // Current fem interpolation context.
86  base_small_vector Normal; // Outward unit normal vector to the
87  // boundary in case of boundary integration
88  scalar_type elt_size; // Estimate of the diameter of the element
89  // if needed.
90  bool need_elt_size;
91  scalar_type coeff; // Coefficient for the Gauss point
92  size_type nbpt, ipt; // Number and index of Gauss point
94  fem_precomp_pool fp_pool;
95  std::map<gauss_pt_corresp, bgeot::pstored_point_tab> neighbor_corresp;
96  std::set<std::pair<std::string,std::string>> unreduced_terms;
97 
98  scalar_type ONE=1;
99 
100  using region_mim_tuple = std::tuple<const mesh_im *, const mesh_region *, psecondary_domain>;
101  struct region_mim : public region_mim_tuple {
102  const mesh_im* mim() const {return std::get<0>(static_cast<region_mim_tuple>(*this));}
103  const mesh_region* region() const {return std::get<1>(static_cast<region_mim_tuple>(*this));}
104  psecondary_domain psd() const {return std::get<2>(static_cast<region_mim_tuple>(*this));}
105 
106  region_mim(const mesh_im *mim_, const mesh_region *region_, psecondary_domain psd)
107  : region_mim_tuple(mim_, region_, psd) {}
108  };
109 
110  std::map<std::string, const base_vector *> extended_vars;
111  std::map<std::string, base_vector> really_extended_vars;
112 
113  struct variable_group_info {
114  const mesh *cached_mesh;
115  const std::string *varname;
116  const mesh_fem *mf;
117  bool reduced_mf;
118  const gmm::sub_interval *I; // sub_interval in the assembled vector/matrix
119  // or in the unreduced vars indexing
120  scalar_type alpha;
121  const base_vector *U; // Vector to read values from
122  variable_group_info()
123  : cached_mesh(0), varname(0), mf(0), reduced_mf(false), I(0) {}
124  };
125 
126  struct interpolate_info {
127  size_type pt_type;
128  bool has_ctx;
129  const mesh *m;
130  fem_interpolation_context ctx;
131  base_node pt_y;
132  base_small_vector Normal;
133  base_matrix G;
134  std::map<std::string, variable_group_info> groups_info;
135  std::map<var_trans_pair, base_tensor> derivatives;
136  std::map<const mesh_fem *, pfem_precomp> pfps;
137  };
138 
139 
140  struct secondary_domain_info {
141  // const mesh *m;
142  papprox_integration pai;
143  fem_interpolation_context ctx;
144  base_small_vector Normal;
145 
146  std::map<std::string, base_vector> local_dofs;
147  std::map<const mesh_fem *, pfem_precomp> pfps;
148  std::map<const mesh_fem *, base_tensor> base;
149  std::map<const mesh_fem *, base_tensor> grad;
150  std::map<const mesh_fem *, base_tensor> hess;
151  };
152 
153 
154  struct elementary_trans_info {
155  base_matrix M;
156  size_type icv;
157  };
158 
159  std::set<std::string> transformations;
160 
161  struct region_mim_instructions {
162 
163  const mesh *m;
164  const mesh_im *im;
165  ga_if_hierarchy current_hierarchy;
166  std::map<std::string, base_vector> local_dofs;
167  std::map<const mesh_fem *, pfem_precomp> pfps;
168  std::map<const mesh_fem *, std::list<ga_if_hierarchy>> pfp_hierarchy;
169  std::map<const mesh_fem *, base_tensor> base;
170  std::map<const mesh_fem *, std::list<ga_if_hierarchy>> base_hierarchy;
171  std::map<const mesh_fem *, base_tensor> grad;
172  std::map<const mesh_fem *, std::list<ga_if_hierarchy>> grad_hierarchy;
173  std::map<const mesh_fem *, base_tensor> hess;
174  std::map<const mesh_fem *, std::list<ga_if_hierarchy>> hess_hierarchy;
175 
176  std::map<const mesh_fem *, base_tensor>
177  xfem_plus_base, xfem_plus_grad, xfem_plus_hess,
178  xfem_minus_base, xfem_minus_grad, xfem_minus_hess;
179  std::map<const mesh_fem *, std::list<ga_if_hierarchy>>
180  xfem_plus_base_hierarchy, xfem_plus_grad_hierarchy,
181  xfem_plus_hess_hierarchy, xfem_minus_base_hierarchy,
182  xfem_minus_grad_hierarchy, xfem_minus_hess_hierarchy;
183 
184  std::map<std::string, std::set<std::string>> transformations;
185  std::set<std::string> transformations_der;
186  std::map<std::string, interpolate_info> interpolate_infos;
187  std::map<std::tuple<std::string, const mesh_fem *, const mesh_fem *>,
188  elementary_trans_info> elementary_trans_infos;
189  secondary_domain_info secondary_domain_infos;
190 
191  std::vector<pga_instruction>
192  begin_instructions, // Instructions being executed at the first Gauss
193  // point after a change of integration method only.
194  elt_instructions, // Instructions executed once per element
195  instructions; // Instructions executed on each
196  // integration/interpolation point
197  std::map<scalar_type, std::list<pga_tree_node> > node_list;
198 
199  region_mim_instructions(): m(0), im(0) {}
200  };
201 
202  std::list<ga_tree> trees; // The trees are stored mainly because they
203  // contain the intermediary tensors.
204  std::list<ga_tree> interpolation_trees;
205 
206  std::map<region_mim, region_mim_instructions> all_instructions;
207 
208  // storage of intermediary tensors for condensation of variables
209  std::list<std::shared_ptr<base_tensor>> condensation_tensors;
210 
211  ga_instruction_set() : need_elt_size(false), nbpt(0), ipt(0) {}
212  };
213 
214 
215  void ga_exec(ga_instruction_set &gis, ga_workspace &workspace);
216  void ga_function_exec(ga_instruction_set &gis);
217  void ga_compile(ga_workspace &workspace, ga_instruction_set &gis,
218  size_type order, bool condensation=false);
219  void ga_compile_function(ga_workspace &workspace,
220  ga_instruction_set &gis, bool scalar);
221  void ga_compile_interpolation(ga_workspace &workspace,
222  ga_instruction_set &gis);
223  void ga_interpolation_exec(ga_instruction_set &gis,
224  ga_workspace &workspace,
225  ga_interpolation_context &gic);
226 
227 } /* end of namespace */
228 
229 
230 #endif /* GETFEM_GENERIC_ASSEMBLY_COMP_EXEC_H__ */
bgeot::size_type
size_t size_type
used as the common size type in the library
Definition: bgeot_poly.h:49
getfem_generic_assembly_semantic.h
Semantic analysis of assembly trees and semantic manipulations.
bgeot::geotrans_precomp_pool
The object geotrans_precomp_pool Allow to allocate a certain number of geotrans_precomp and automatic...
Definition: bgeot_geometric_trans.h:383
getfem
GEneric Tool for Finite Element Methods.
Definition: getfem_accumulated_distro.h:46
bgeot::alpha
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:47
bgeot::pgeometric_trans
std::shared_ptr< const bgeot::geometric_trans > pgeometric_trans
pointer type for a geometric transformation
Definition: bgeot_geometric_trans.h:186