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 
27 // C++ includes
28 #include <unordered_map>
29 #include <vector>
30 #include <map>
31 #include <set>
32 
33 namespace libMesh
34 {
35 
36 class RBParameters;
37 class Point;
38 class System;
39 
47 {
48  VectorizedEvalInput () = default;
49  VectorizedEvalInput (const VectorizedEvalInput &) = default;
53  virtual ~VectorizedEvalInput() = default;
54 
58  void clear();
59 
73  std::vector<Point> all_xyz;
74  std::vector<dof_id_type> elem_ids;
75  std::vector<unsigned int> qps;
76  std::vector<subdomain_id_type> sbd_ids;
77  std::vector<std::vector<Point>> all_xyz_perturb;
78  std::vector<std::vector<Real>> phi_i_qp;
79  std::vector<unsigned int> side_indices;
80  std::vector<boundary_id_type> boundary_ids;
81  std::vector<dof_id_type> node_ids;
82  std::vector<ElemType> elem_types;
83  std::vector<std::vector<Real>> JxW_all_qp;
84  std::vector<std::vector<std::vector<Real>>> phi_i_all_qp;
85 };
86 
95 {
96 public:
97 
102 
112  virtual ~RBParametrizedFunction();
113 
119  virtual unsigned int get_n_components() const = 0;
120 
132  virtual Number evaluate_comp(const RBParameters & mu,
133  unsigned int comp,
134  const Point & xyz,
135  dof_id_type elem_id,
136  unsigned int qp,
137  subdomain_id_type subdomain_id,
138  const std::vector<Point> & xyz_perturb,
139  const std::vector<Real> & phi_i_qp);
140 
144  virtual Number side_evaluate_comp(const RBParameters & mu,
145  unsigned int comp,
146  const Point & xyz,
147  dof_id_type elem_id,
148  unsigned int side_index,
149  unsigned int qp,
150  subdomain_id_type subdomain_id,
151  boundary_id_type boundary_id,
152  const std::vector<Point> & xyz_perturb,
153  const std::vector<Real> & phi_i_qp);
154 
158  virtual Number node_evaluate_comp(const RBParameters & mu,
159  unsigned int comp,
160  const Point & xyz,
161  dof_id_type node_id,
162  boundary_id_type boundary_id);
163 
171  virtual std::vector<Number> evaluate(const RBParameters & mu,
172  const Point & xyz,
173  dof_id_type elem_id,
174  unsigned int qp,
175  subdomain_id_type subdomain_id,
176  const std::vector<Point> & xyz_perturb,
177  const std::vector<Real> & phi_i_qp);
178 
182  virtual std::vector<Number> side_evaluate(const RBParameters & mu,
183  const Point & xyz,
184  dof_id_type elem_id,
185  unsigned int side_index,
186  unsigned int qp,
187  subdomain_id_type subdomain_id,
188  boundary_id_type boundary_id,
189  const std::vector<Point> & xyz_perturb,
190  const std::vector<Real> & phi_i_qp);
191 
195  virtual std::vector<Number> node_evaluate(const RBParameters & mu,
196  const Point & xyz,
197  dof_id_type node_id,
198  boundary_id_type boundary_id);
199 
207  virtual void vectorized_evaluate(const std::vector<RBParameters> & mus,
208  const VectorizedEvalInput & v,
209  std::vector<std::vector<std::vector<Number>>> & output);
210 
218  virtual void side_vectorized_evaluate(const std::vector<RBParameters> & mus,
219  const VectorizedEvalInput & v,
220  std::vector<std::vector<std::vector<Number>>> & output);
221 
229  virtual void node_vectorized_evaluate(const std::vector<RBParameters> & mus,
230  const VectorizedEvalInput & v,
231  std::vector<std::vector<std::vector<Number>>> & output);
232 
239  const std::unordered_map<dof_id_type, std::vector<Point>> & all_xyz,
240  const std::unordered_map<dof_id_type, subdomain_id_type> & sbd_ids,
241  const std::unordered_map<dof_id_type, std::vector<std::vector<Point>> > & all_xyz_perturb,
242  const System & sys);
243 
248  const std::map<std::pair<dof_id_type,unsigned int>, std::vector<Point>> & side_all_xyz,
249  const std::map<std::pair<dof_id_type,unsigned int>, subdomain_id_type> & sbd_ids,
250  const std::map<std::pair<dof_id_type,unsigned int>, boundary_id_type> & side_boundary_ids,
251  const std::map<std::pair<dof_id_type,unsigned int>, unsigned int> & side_types,
252  const std::map<std::pair<dof_id_type,unsigned int>, std::vector<std::vector<Point>> > & side_all_xyz_perturb,
253  const System & sys);
254 
259  const std::unordered_map<dof_id_type, Point> & all_xyz,
260  const std::unordered_map<dof_id_type, boundary_id_type> & node_boundary_ids,
261  const System & sys);
262 
267  virtual Number lookup_preevaluated_value_on_mesh(unsigned int comp,
268  dof_id_type elem_id,
269  unsigned int qp) const;
270 
275  virtual Number lookup_preevaluated_side_value_on_mesh(unsigned int comp,
276  dof_id_type elem_id,
277  unsigned int side_index,
278  unsigned int qp) const;
279 
284  virtual Number lookup_preevaluated_node_value_on_mesh(unsigned int comp,
285  dof_id_type node_id) const;
286 
292  virtual void initialize_lookup_table();
293 
298  Number get_parameter_independent_data(const std::string & property_name,
299  subdomain_id_type sbd_id) const;
300 
305  const std::set<boundary_id_type> & get_parametrized_function_boundary_ids() const;
306  void set_parametrized_function_boundary_ids(const std::set<boundary_id_type> & boundary_ids, bool is_nodal_boundary);
307 
311  bool on_mesh_sides() const;
312 
316  bool on_mesh_nodes() const;
317 
339  virtual void get_spatial_indices(std::vector<std::vector<unsigned int>> & spatial_indices,
340  const VectorizedEvalInput & v);
341 
347  virtual void initialize_spatial_indices(const std::vector<std::vector<unsigned int>> & spatial_indices,
348  const VectorizedEvalInput & v);
349 
357 
362  std::vector<std::vector<std::vector<Number>>> preevaluated_values;
363 
372  std::unordered_map<dof_id_type, std::vector<unsigned int>> mesh_to_preevaluated_values_map;
373 
379  std::map<std::pair<dof_id_type,unsigned int>, std::vector<unsigned int>> mesh_to_preevaluated_side_values_map;
380 
387  std::unordered_map<dof_id_type, unsigned int> mesh_to_preevaluated_node_values_map;
388 
396 
404 
411 
417 
423 
424 protected:
425 
433  std::map<std::string, std::map<subdomain_id_type, Number>> _parameter_independent_data;
434 
439  std::set<boundary_id_type> _parametrized_function_boundary_ids;
440 
447 
448 };
449 
450 }
451 
452 #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< std::vector< Real > > JxW_all_qp
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
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.
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
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
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.
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...