libMesh
rb_parametrized_function.h
Go to the documentation of this file.
1 // rbOOmit: An implementation of the Certified Reduced Basis method.
2 // Copyright (C) 2009, 2010 David J. Knezevic
3 
4 // This file is part of rbOOmit.
5 
6 // rbOOmit is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 
11 // rbOOmit is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
15 
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 
20 #ifndef LIBMESH_RB_PARAMETRIZED_FUNCTION_H
21 #define LIBMESH_RB_PARAMETRIZED_FUNCTION_H
22 
23 // libMesh includes
24 #include "libmesh/libmesh_common.h"
25 #include "libmesh/enum_elem_type.h"
26 #include "libmesh/enum_order.h"
27 
28 // C++ includes
29 #include <unordered_map>
30 #include <vector>
31 #include <map>
32 #include <set>
33 
34 namespace libMesh
35 {
36 
37 class RBParameters;
38 class Point;
39 class System;
40 
41 namespace Parallel {
42  class Communicator;
43 }
44 
52 {
53  VectorizedEvalInput () = default;
54  VectorizedEvalInput (const VectorizedEvalInput &) = default;
58  virtual ~VectorizedEvalInput() = default;
59 
63  void clear();
64 
78  std::vector<Point> all_xyz;
79  std::vector<dof_id_type> elem_ids;
80  std::vector<unsigned int> qps;
81  std::vector<subdomain_id_type> sbd_ids;
82  std::vector<std::vector<Point>> all_xyz_perturb;
83  std::vector<std::vector<Real>> phi_i_qp;
84  std::vector<unsigned int> side_indices;
85  std::vector<boundary_id_type> boundary_ids;
86  std::vector<dof_id_type> node_ids;
87  std::vector<ElemType> elem_types;
92  std::map<dof_id_type, unsigned int> elem_id_to_local_index;
93  std::vector<std::vector<Real>> JxW_all_qp;
94  std::vector<std::vector<std::vector<Real>>> phi_i_all_qp;
95  std::vector<Point> dxyzdxi_elem_center;
96  std::vector<Point> dxyzdeta_elem_center;
97  std::vector<Order> qrule_orders;
98 
104  std::unordered_map<std::string, std::set<dof_id_type>> rb_property_map;
105 };
106 
115 {
116 public:
117 
122 
132  virtual ~RBParametrizedFunction();
133 
139  virtual unsigned int get_n_components() const = 0;
140 
152  virtual Number evaluate_comp(const RBParameters & mu,
153  unsigned int comp,
154  const Point & xyz,
155  dof_id_type elem_id,
156  unsigned int qp,
157  subdomain_id_type subdomain_id,
158  const std::vector<Point> & xyz_perturb,
159  const std::vector<Real> & phi_i_qp);
160 
164  virtual Number side_evaluate_comp(const RBParameters & mu,
165  unsigned int comp,
166  const Point & xyz,
167  dof_id_type elem_id,
168  unsigned int side_index,
169  unsigned int qp,
170  subdomain_id_type subdomain_id,
171  boundary_id_type boundary_id,
172  const std::vector<Point> & xyz_perturb,
173  const std::vector<Real> & phi_i_qp);
174 
178  virtual Number node_evaluate_comp(const RBParameters & mu,
179  unsigned int comp,
180  const Point & xyz,
181  dof_id_type node_id,
182  boundary_id_type boundary_id);
183 
191  virtual std::vector<Number> evaluate(const RBParameters & mu,
192  const Point & xyz,
193  dof_id_type elem_id,
194  unsigned int qp,
195  subdomain_id_type subdomain_id,
196  const std::vector<Point> & xyz_perturb,
197  const std::vector<Real> & phi_i_qp);
198 
202  virtual std::vector<Number> side_evaluate(const RBParameters & mu,
203  const Point & xyz,
204  dof_id_type elem_id,
205  unsigned int side_index,
206  unsigned int qp,
207  subdomain_id_type subdomain_id,
208  boundary_id_type boundary_id,
209  const std::vector<Point> & xyz_perturb,
210  const std::vector<Real> & phi_i_qp);
211 
215  virtual std::vector<Number> node_evaluate(const RBParameters & mu,
216  const Point & xyz,
217  dof_id_type node_id,
218  boundary_id_type boundary_id);
219 
227  virtual void vectorized_evaluate(const std::vector<RBParameters> & mus,
228  const VectorizedEvalInput & v,
229  std::vector<std::vector<std::vector<Number>>> & output);
230 
238  virtual void side_vectorized_evaluate(const std::vector<RBParameters> & mus,
239  const VectorizedEvalInput & v,
240  std::vector<std::vector<std::vector<Number>>> & output);
241 
249  virtual void node_vectorized_evaluate(const std::vector<RBParameters> & mus,
250  const VectorizedEvalInput & v,
251  std::vector<std::vector<std::vector<Number>>> & output);
252 
259  const std::unordered_map<dof_id_type, std::vector<Point>> & all_xyz,
260  const std::unordered_map<dof_id_type, subdomain_id_type> & sbd_ids,
261  const std::unordered_map<dof_id_type, std::vector<std::vector<Point>> > & all_xyz_perturb,
262  const System & sys);
263 
268  const std::map<std::pair<dof_id_type,unsigned int>, std::vector<Point>> & side_all_xyz,
269  const std::map<std::pair<dof_id_type,unsigned int>, subdomain_id_type> & sbd_ids,
270  const std::map<std::pair<dof_id_type,unsigned int>, boundary_id_type> & side_boundary_ids,
271  const std::map<std::pair<dof_id_type,unsigned int>, unsigned int> & side_types,
272  const std::map<std::pair<dof_id_type,unsigned int>, std::vector<std::vector<Point>> > & side_all_xyz_perturb,
273  const System & sys);
274 
279  const std::unordered_map<dof_id_type, Point> & all_xyz,
280  const std::unordered_map<dof_id_type, boundary_id_type> & node_boundary_ids,
281  const System & sys);
282 
287  virtual Number lookup_preevaluated_value_on_mesh(unsigned int comp,
288  dof_id_type elem_id,
289  unsigned int qp) const;
290 
295  virtual Number lookup_preevaluated_side_value_on_mesh(unsigned int comp,
296  dof_id_type elem_id,
297  unsigned int side_index,
298  unsigned int qp) const;
299 
304  virtual Number lookup_preevaluated_node_value_on_mesh(unsigned int comp,
305  dof_id_type node_id) const;
306 
312  virtual void initialize_lookup_table();
313 
318  Number get_parameter_independent_data(const std::string & property_name,
319  subdomain_id_type sbd_id) const;
320 
325  const std::set<boundary_id_type> & get_parametrized_function_boundary_ids() const;
326  void set_parametrized_function_boundary_ids(const std::set<boundary_id_type> & boundary_ids, bool is_nodal_boundary);
327 
331  bool on_mesh_sides() const;
332 
336  bool on_mesh_nodes() const;
337 
359  virtual void get_spatial_indices(std::vector<std::vector<unsigned int>> & spatial_indices,
360  const VectorizedEvalInput & v);
361 
367  virtual void initialize_spatial_indices(const std::vector<std::vector<unsigned int>> & spatial_indices,
368  const VectorizedEvalInput & v);
369 
377 
381  const std::unordered_map<std::string, std::set<dof_id_type>> & get_rb_property_map() const;
382 
387  void add_rb_property_map_entry(std::string & property_name, std::set<dof_id_type> & entity_ids);
388 
394  const Parallel::Communicator & comm,
395  std::unordered_map<std::string, std::set<dof_id_type>> & rb_property_map,
396  dof_id_type elem_id);
397 
402  std::vector<std::vector<std::vector<Number>>> preevaluated_values;
403 
412  std::unordered_map<dof_id_type, std::vector<unsigned int>> mesh_to_preevaluated_values_map;
413 
419  std::map<std::pair<dof_id_type,unsigned int>, std::vector<unsigned int>> mesh_to_preevaluated_side_values_map;
420 
427  std::unordered_map<dof_id_type, unsigned int> mesh_to_preevaluated_node_values_map;
428 
436 
444 
450 
457 
463 
469 
470 protected:
471 
479  std::map<std::string, std::map<subdomain_id_type, Number>> _parameter_independent_data;
480 
485  std::set<boundary_id_type> _parametrized_function_boundary_ids;
486 
493 
500  std::unordered_map<std::string, std::set<dof_id_type>> _rb_property_map;
501 };
502 
503 }
504 
505 #endif // LIBMESH_RB_PARAMETRIZED_FUNCTION_H
virtual unsigned int get_n_components() const =0
Specify the number of components in this parametrized function.
virtual void get_spatial_indices(std::vector< std::vector< unsigned int >> &spatial_indices, const VectorizedEvalInput &v)
In some cases a parametrized function is defined based on array data that we index into based on the ...
std::vector< ElemType > elem_types
virtual void preevaluate_parametrized_function_on_mesh_sides(const RBParameters &mu, const std::map< std::pair< dof_id_type, unsigned int >, std::vector< Point >> &side_all_xyz, const std::map< std::pair< dof_id_type, unsigned int >, subdomain_id_type > &sbd_ids, const std::map< std::pair< dof_id_type, unsigned int >, boundary_id_type > &side_boundary_ids, const std::map< std::pair< dof_id_type, unsigned int >, unsigned int > &side_types, const std::map< std::pair< dof_id_type, unsigned int >, std::vector< std::vector< Point >> > &side_all_xyz_perturb, const System &sys)
Same as preevaluate_parametrized_function_on_mesh() except for mesh sides.
virtual void initialize_spatial_indices(const std::vector< std::vector< unsigned int >> &spatial_indices, const VectorizedEvalInput &v)
The Online stage counterpart of get_spatial_indices().
VectorizedEvalInput & operator=(const VectorizedEvalInput &)=default
std::vector< Point > dxyzdeta_elem_center
std::vector< std::vector< Real > > JxW_all_qp
virtual void add_interpolation_data_to_rb_property_map(const Parallel::Communicator &comm, std::unordered_map< std::string, std::set< dof_id_type >> &rb_property_map, dof_id_type elem_id)
Virtual function that can be overridden in RBParametrizedFunction subclasses to store properties in t...
void set_parametrized_function_boundary_ids(const std::set< boundary_id_type > &boundary_ids, bool is_nodal_boundary)
std::unordered_map< dof_id_type, unsigned int > mesh_to_preevaluated_node_values_map
Indexing into preevaluated_values for the case where the preevaluated values were obtained from evalu...
const std::set< boundary_id_type > & get_parametrized_function_boundary_ids() const
For RBParametrizedFunctions defined on element sides or nodes, we get/set the boundary IDs that this ...
std::vector< unsigned int > qps
A simple functor class that provides a RBParameter-dependent function.
std::set< boundary_id_type > _parametrized_function_boundary_ids
In the case of an RBParametrizedFunction defined on element sides, this defines the set of boundary I...
std::vector< std::vector< Real > > phi_i_qp
std::map< dof_id_type, unsigned int > elem_id_to_local_index
The following containers are indexed by element id to avoid duplicated data.
std::unordered_map< std::string, std::set< dof_id_type > > _rb_property_map
Generic property map used to store data during mesh pre-evaluation.
virtual void side_vectorized_evaluate(const std::vector< RBParameters > &mus, const VectorizedEvalInput &v, std::vector< std::vector< std::vector< Number >>> &output)
Same as vectorized_evaluate() but on element sides.
std::vector< dof_id_type > elem_ids
The libMesh namespace provides an interface to certain functionality in the library.
Define a struct for the input to the "vectorized evaluate" functions below.
const std::unordered_map< std::string, std::set< dof_id_type > > & get_rb_property_map() const
Function that returns a reference to the rb_property_map stored in the RBParametrizedFunction.
virtual void preevaluate_parametrized_function_on_mesh(const RBParameters &mu, const std::unordered_map< dof_id_type, std::vector< Point >> &all_xyz, const std::unordered_map< dof_id_type, subdomain_id_type > &sbd_ids, const std::unordered_map< dof_id_type, std::vector< std::vector< Point >> > &all_xyz_perturb, const System &sys)
Store the result of vectorized_evaluate.
virtual Number lookup_preevaluated_value_on_mesh(unsigned int comp, dof_id_type elem_id, unsigned int qp) const
Look up the preevaluate values of the parametrized function for component comp, element elem_id...
std::vector< subdomain_id_type > sbd_ids
void add_rb_property_map_entry(std::string &property_name, std::set< dof_id_type > &entity_ids)
Function that adds a property to the RBParametrizedFunction rb_property_map.
bool is_lookup_table
Boolean to indicate if this parametrized function is defined based on a lookup table or not...
std::string lookup_table_param_name
If this is a lookup table, then lookup_table_param_name specifies the parameter that is used to index...
virtual Number side_evaluate_comp(const RBParameters &mu, unsigned int comp, const Point &xyz, dof_id_type elem_id, unsigned int side_index, unsigned int qp, subdomain_id_type subdomain_id, boundary_id_type boundary_id, const std::vector< Point > &xyz_perturb, const std::vector< Real > &phi_i_qp)
Same as evaluate_comp() but for element sides.
std::vector< unsigned int > side_indices
int8_t boundary_id_type
Definition: id_types.h:51
std::unordered_map< std::string, std::set< dof_id_type > > rb_property_map
Generic map that can be used to store any list of ids (elements, nodes, elemsets, subdomains...
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:96
virtual Number lookup_preevaluated_side_value_on_mesh(unsigned int comp, dof_id_type elem_id, unsigned int side_index, unsigned int qp) const
Look up the preevaluated values of the parametrized function for component comp, element elem_id...
virtual Number node_evaluate_comp(const RBParameters &mu, unsigned int comp, const Point &xyz, dof_id_type node_id, boundary_id_type boundary_id)
Same as evaluate_comp() but for element nodes.
std::vector< Point > all_xyz
The members that define the inputs to the vectorized evaluate functions.
virtual std::vector< Number > side_evaluate(const RBParameters &mu, const Point &xyz, dof_id_type elem_id, unsigned int side_index, unsigned int qp, subdomain_id_type subdomain_id, boundary_id_type boundary_id, const std::vector< Point > &xyz_perturb, const std::vector< Real > &phi_i_qp)
Same as evaluate() but for element sides.
std::map< std::string, std::map< subdomain_id_type, Number > > _parameter_independent_data
In some cases we need to store parameter-independent data which is related to this function but since...
bool requires_all_elem_qp_data
Boolean to indicate whether this parametrized function requires data from all qps on the current elem...
virtual void preevaluate_parametrized_function_cleanup()
Virtual function that performs cleanup after each "preevaluate parametrized function" evaluation...
This class is part of the rbOOmit framework.
Definition: rb_parameters.h:52
std::vector< std::vector< std::vector< Real > > > phi_i_all_qp
virtual Number evaluate_comp(const RBParameters &mu, unsigned int comp, const Point &xyz, dof_id_type elem_id, unsigned int qp, subdomain_id_type subdomain_id, const std::vector< Point > &xyz_perturb, const std::vector< Real > &phi_i_qp)
Evaluate the parametrized function at the specified point for parameter mu.
bool requires_all_elem_center_data
Boolean to indicate whether this parametrized function requires data from the center on the current e...
std::vector< Point > dxyzdxi_elem_center
std::map< std::pair< dof_id_type, unsigned int >, std::vector< unsigned int > > mesh_to_preevaluated_side_values_map
Similar to the above except this map stores the data on element sides.
bool requires_xyz_perturbations
Boolean to indicate whether this parametrized function requires xyz perturbations in order to evaluat...
virtual void preevaluate_parametrized_function_on_mesh_nodes(const RBParameters &mu, const std::unordered_map< dof_id_type, Point > &all_xyz, const std::unordered_map< dof_id_type, boundary_id_type > &node_boundary_ids, const System &sys)
Same as preevaluate_parametrized_function_on_mesh() except for mesh nodes.
void clear()
Clear all the members.
bool _is_nodal_boundary
In the case that _parametrized_function_boundary_ids is not empty, then this parametrized function is...
virtual ~VectorizedEvalInput()=default
RBParametrizedFunction & operator=(const RBParametrizedFunction &)=default
Number get_parameter_independent_data(const std::string &property_name, subdomain_id_type sbd_id) const
Get the value stored in _parameter_independent_data associated with region_name and property_name...
std::vector< std::vector< std::vector< Number > > > preevaluated_values
Storage for pre-evaluated values.
std::vector< boundary_id_type > boundary_ids
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::vector< std::vector< Point > > all_xyz_perturb
virtual void node_vectorized_evaluate(const std::vector< RBParameters > &mus, const VectorizedEvalInput &v, std::vector< std::vector< std::vector< Number >>> &output)
Same as vectorized_evaluate() but on element nodes.
virtual Number lookup_preevaluated_node_value_on_mesh(unsigned int comp, dof_id_type node_id) const
Look up the preevaluate values of the parametrized function for component comp, node node_id...
virtual std::vector< Number > evaluate(const RBParameters &mu, const Point &xyz, dof_id_type elem_id, unsigned int qp, subdomain_id_type subdomain_id, const std::vector< Point > &xyz_perturb, const std::vector< Real > &phi_i_qp)
Evaluate the parametrized function at the specified point for parameter mu.
std::unordered_map< dof_id_type, std::vector< unsigned int > > mesh_to_preevaluated_values_map
Indexing into preevaluated_values for the case where the preevaluated values were obtained from evalu...
virtual void initialize_lookup_table()
If this parametrized function is defined based on a lookup table then we can call this function to in...
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39
virtual std::vector< Number > node_evaluate(const RBParameters &mu, const Point &xyz, dof_id_type node_id, boundary_id_type boundary_id)
Same as evaluate() but for element nodes.
std::vector< dof_id_type > node_ids
uint8_t dof_id_type
Definition: id_types.h:67
virtual void vectorized_evaluate(const std::vector< RBParameters > &mus, const VectorizedEvalInput &v, std::vector< std::vector< std::vector< Number >>> &output)
Vectorized version of evaluate.
Real fd_delta
The finite difference step size in the case that this function in the case that this function uses fi...