libMesh
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Attributes | List of all members
libMesh::RBParametrizedFunction Class Referenceabstract

A simple functor class that provides a RBParameter-dependent function. More...

#include <rb_parametrized_function.h>

Inheritance diagram for libMesh::RBParametrizedFunction:
[legend]

Public Member Functions

 RBParametrizedFunction ()
 Constructor.
 
 RBParametrizedFunction (RBParametrizedFunction &&)=default
 Special functions.
 
 RBParametrizedFunction (const RBParametrizedFunction &)=default
 
RBParametrizedFunctionoperator= (const RBParametrizedFunction &)=default
 
RBParametrizedFunctionoperator= (RBParametrizedFunction &&)=default
 
virtual ~RBParametrizedFunction ()
 
virtual unsigned int get_n_components () const =0
 Specify the number of components in this parametrized function.
 
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.
 
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.
 
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.
 
virtual std::vector< Numberevaluate (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.
 
virtual std::vector< Numberside_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.
 
virtual std::vector< Numbernode_evaluate (const RBParameters &mu, const Point &xyz, dof_id_type node_id, boundary_id_type boundary_id)
 Same as evaluate() but for element nodes.
 
virtual void vectorized_evaluate (const std::vector< RBParameters > &mus, const VectorizedEvalInput &v, std::vector< std::vector< std::vector< Number > > > &output)
 Vectorized version of evaluate.
 
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.
 
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 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 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 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.
 
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, and quadrature point qp.
 
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, side_index, and quadrature point qp.
 
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 void initialize_lookup_table ()
 If this parametrized function is defined based on a lookup table then we can call this function to initialize the table.
 
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.
 
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 parametrized function is defined on.
 
void set_parametrized_function_boundary_ids (const std::set< boundary_id_type > &boundary_ids, bool is_nodal_boundary)
 
bool on_mesh_sides () const
 
bool on_mesh_nodes () const
 
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 spatial data from the mesh (e.g.
 
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().
 
virtual void preevaluate_parametrized_function_cleanup ()
 Virtual function that performs cleanup after each "preevaluate parametrized function" evaluation.
 
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.
 
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.
 
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 the rb_property_map.
 

Public Attributes

std::vector< std::vector< std::vector< Number > > > preevaluated_values
 Storage for pre-evaluated values.
 
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 evaluations at elements/quadrature points on a mesh.
 
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.
 
std::unordered_map< dof_id_type, unsigned intmesh_to_preevaluated_node_values_map
 Indexing into preevaluated_values for the case where the preevaluated values were obtained from evaluations at elements/quadrature points on a mesh.
 
bool requires_xyz_perturbations
 Boolean to indicate whether this parametrized function requires xyz perturbations in order to evaluate function values.
 
bool requires_all_elem_qp_data
 Boolean to indicate whether this parametrized function requires data from all qps on the current element at each qp location.
 
bool requires_all_elem_center_data
 Boolean to indicate whether this parametrized function requires data from the center on the current element.
 
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 into the lookup table.
 
Real fd_delta
 The finite difference step size in the case that this function in the case that this function uses finite differencing.
 

Protected Attributes

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 it is parameter-indepedent should not be returned as part of evaluate().
 
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 IDs that the function is defined on.
 
bool _is_nodal_boundary
 In the case that _parametrized_function_boundary_ids is not empty, then this parametrized function is defined on a mesh boundary.
 
std::unordered_map< std::string, std::set< dof_id_type > > _rb_property_map
 Generic property map used to store data during mesh pre-evaluation.
 

Detailed Description

A simple functor class that provides a RBParameter-dependent function.

Author
David Knezevic
Date
2012

Provides a reduced basis parameterized function.

Definition at line 114 of file rb_parametrized_function.h.

Constructor & Destructor Documentation

◆ RBParametrizedFunction() [1/3]

libMesh::RBParametrizedFunction::RBParametrizedFunction ( )

Constructor.

Definition at line 59 of file rb_parametrized_function.C.

60:
64is_lookup_table(false),
65fd_delta(1.e-6),
67{}
bool is_lookup_table
Boolean to indicate if this parametrized function is defined based on a lookup table or not.
Real fd_delta
The finite difference step size in the case that this function in the case that this function uses fi...
bool _is_nodal_boundary
In the case that _parametrized_function_boundary_ids is not empty, then this parametrized function is...
bool requires_all_elem_qp_data
Boolean to indicate whether this parametrized function requires data from all qps on the current elem...
bool requires_xyz_perturbations
Boolean to indicate whether this parametrized function requires xyz perturbations in order to evaluat...
bool requires_all_elem_center_data
Boolean to indicate whether this parametrized function requires data from the center on the current e...

◆ RBParametrizedFunction() [2/3]

libMesh::RBParametrizedFunction::RBParametrizedFunction ( RBParametrizedFunction &&  )
default

Special functions.

  • This class can be default copy/move assigned/constructed.
  • The destructor is defaulted out-of-line.

◆ RBParametrizedFunction() [3/3]

libMesh::RBParametrizedFunction::RBParametrizedFunction ( const RBParametrizedFunction )
default

◆ ~RBParametrizedFunction()

libMesh::RBParametrizedFunction::~RBParametrizedFunction ( )
virtualdefault

Member Function Documentation

◆ add_interpolation_data_to_rb_property_map()

void libMesh::RBParametrizedFunction::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

Virtual function that can be overridden in RBParametrizedFunction subclasses to store properties in the rb_property_map.

Definition at line 844 of file rb_parametrized_function.C.

848{
849 // No-op by default
850}

Referenced by libMesh::RBEIMEvaluation::add_interpolation_data().

◆ add_rb_property_map_entry()

void libMesh::RBParametrizedFunction::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.

The function checks that there is no duplicated properties before adding the property to the map.

Definition at line 838 of file rb_parametrized_function.C.

839{
840 bool insert_succeed = _rb_property_map.insert({property_name, entity_ids}).second;
841 libmesh_error_msg_if(!insert_succeed, "Entry already added, duplicate detected.");
842}
std::unordered_map< std::string, std::set< dof_id_type > > _rb_property_map
Generic property map used to store data during mesh pre-evaluation.

References _rb_property_map.

◆ evaluate()

std::vector< Number > libMesh::RBParametrizedFunction::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 
)
virtual

Evaluate the parametrized function at the specified point for parameter mu.

If requires_xyz_perturbations==false, then xyz_perturb will not be used.

In this case we evaluate for all components.

Definition at line 122 of file rb_parametrized_function.C.

129{
130 // This method should be overridden in subclasses, so we just give a not implemented error message here
131 libmesh_not_implemented();
132
133 return std::vector<Number>();
134}

Referenced by evaluate_comp(), and vectorized_evaluate().

◆ evaluate_comp()

Number libMesh::RBParametrizedFunction::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 
)
virtual

Evaluate the parametrized function at the specified point for parameter mu.

If requires_xyz_perturbations==false, then xyz_perturb will not be used.

In this case we return the value for component comp only, but the base class implementation simply calls the vector-returning evaluate() function below and returns the comp'th component, so derived classes should provide a more efficient routine or just call the vector-returning function instead.

Definition at line 72 of file rb_parametrized_function.C.

80{
81 std::vector<Number> values = evaluate(mu, xyz, elem_id, qp, subdomain_id, xyz_perturb, phi_i_qp);
82
83 libmesh_error_msg_if(comp >= values.size(), "Error: Invalid value of comp");
84
85 return values[comp];
86}
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.

References evaluate().

◆ get_n_components()

virtual unsigned int libMesh::RBParametrizedFunction::get_n_components ( ) const
pure virtual

Specify the number of components in this parametrized function.

A scalar-valued function has one component, a vector-valued function has more than one component.

Implemented in ShiftedGaussian, and Gxyz.

Referenced by libMesh::RBEIMConstruction::initialize_parametrized_functions_in_training_set(), node_vectorized_evaluate(), side_vectorized_evaluate(), and vectorized_evaluate().

◆ get_parameter_independent_data()

Number libMesh::RBParametrizedFunction::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.

Definition at line 810 of file rb_parametrized_function.C.

812{
813 return libmesh_map_find(libmesh_map_find(_parameter_independent_data, property_name), sbd_id);
814}
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...

References _parameter_independent_data.

◆ get_parametrized_function_boundary_ids()

const std::set< boundary_id_type > & libMesh::RBParametrizedFunction::get_parametrized_function_boundary_ids ( ) const

For RBParametrizedFunctions defined on element sides or nodes, we get/set the boundary IDs that this parametrized function is defined on.

Definition at line 852 of file rb_parametrized_function.C.

853{
855}
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...

References _parametrized_function_boundary_ids.

Referenced by libMesh::RBEIMConstruction::initialize_qp_data(), libMesh::RBEIMEvaluation::node_distribute_bfs(), on_mesh_nodes(), on_mesh_sides(), and libMesh::RBEIMEvaluation::side_distribute_bfs().

◆ get_rb_property_map()

const std::unordered_map< std::string, std::set< dof_id_type > > & libMesh::RBParametrizedFunction::get_rb_property_map ( ) const

Function that returns a reference to the rb_property_map stored in the RBParametrizedFunction.

Definition at line 833 of file rb_parametrized_function.C.

834{
835 return _rb_property_map;
836}

References _rb_property_map.

Referenced by libMesh::RBEIMEvaluation::initialize_rb_property_map().

◆ get_spatial_indices()

void libMesh::RBParametrizedFunction::get_spatial_indices ( std::vector< std::vector< unsigned int > > &  spatial_indices,
const VectorizedEvalInput v 
)
virtual

In some cases a parametrized function is defined based on array data that we index into based on the spatial data from the mesh (e.g.

element, node, or side indices). We refer to the indices that we use to index into this array data as "spatial indices". This method sets spatial_indices based on the provided mesh-based indices.

Note that spatial_indices is defined as a doubly-nested vector so that we can handle the case where the spatial function evaluation requires us to have indices from all nodes of an element, since in that case we need a vector of indices (one per node) for each point. Other cases, such as when we define the parametrized function based on the element index only, only require a singly-nested vector which we handle as a special case of the doubly-nested vector.

This method is typically used in the Offline stage in order to generate and store the relevant spatial indices.

This method is a no-op by default, but it can be overridden in subclasses to provide the relevant behavior.

Definition at line 816 of file rb_parametrized_function.C.

818{
819 // No-op by default
820}

Referenced by libMesh::RBEIMEvaluation::initialize_interpolation_points_spatial_indices().

◆ initialize_lookup_table()

void libMesh::RBParametrizedFunction::initialize_lookup_table ( )
virtual

If this parametrized function is defined based on a lookup table then we can call this function to initialize the table.

This is a no-op by default, but it can be overridden in subclasses as needed.

Definition at line 805 of file rb_parametrized_function.C.

806{
807 // No-op by default, override in subclasses as needed
808}

Referenced by libMesh::RBEIMConstruction::initialize_parametrized_functions_in_training_set().

◆ initialize_spatial_indices()

void libMesh::RBParametrizedFunction::initialize_spatial_indices ( const std::vector< std::vector< unsigned int > > &  spatial_indices,
const VectorizedEvalInput v 
)
virtual

The Online stage counterpart of get_spatial_indices().

This method is used to initialize the spatial index data in this object so that we can evaluate it during an Online solve.

Definition at line 822 of file rb_parametrized_function.C.

824{
825 // No-op by default
826}

Referenced by libMesh::RBEIMEvaluation::initialize_param_fn_spatial_indices().

◆ lookup_preevaluated_node_value_on_mesh()

Number libMesh::RBParametrizedFunction::lookup_preevaluated_node_value_on_mesh ( unsigned int  comp,
dof_id_type  node_id 
) const
virtual

Look up the preevaluate values of the parametrized function for component comp, node node_id.

Definition at line 793 of file rb_parametrized_function.C.

795{
796 unsigned int index =
797 libmesh_map_find(mesh_to_preevaluated_node_values_map, node_id);
798
799 libmesh_error_msg_if(preevaluated_values.size() != 1, "Error: we expect only one parameter index");
800 libmesh_error_msg_if(index >= preevaluated_values[0].size(), "Error: invalid index");
801
802 return preevaluated_values[0][index][comp];
803}
std::vector< std::vector< std::vector< Number > > > preevaluated_values
Storage for pre-evaluated values.
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...

References mesh_to_preevaluated_node_values_map, and preevaluated_values.

Referenced by libMesh::RBEIMConstruction::initialize_parametrized_functions_in_training_set().

◆ lookup_preevaluated_side_value_on_mesh()

Number libMesh::RBParametrizedFunction::lookup_preevaluated_side_value_on_mesh ( unsigned int  comp,
dof_id_type  elem_id,
unsigned int  side_index,
unsigned int  qp 
) const
virtual

Look up the preevaluated values of the parametrized function for component comp, element elem_id, side_index, and quadrature point qp.

Definition at line 776 of file rb_parametrized_function.C.

780{
781 const std::vector<unsigned int> & indices_at_qps =
782 libmesh_map_find(mesh_to_preevaluated_side_values_map, std::make_pair(elem_id,side_index));
783
784 libmesh_error_msg_if(qp >= indices_at_qps.size(), "Error: invalid qp");
785
786 unsigned int index = indices_at_qps[qp];
787 libmesh_error_msg_if(preevaluated_values.size() != 1, "Error: we expect only one parameter index");
788 libmesh_error_msg_if(index >= preevaluated_values[0].size(), "Error: invalid index");
789
790 return preevaluated_values[0][index][comp];
791}
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.

References mesh_to_preevaluated_side_values_map, and preevaluated_values.

Referenced by libMesh::RBEIMConstruction::initialize_parametrized_functions_in_training_set().

◆ lookup_preevaluated_value_on_mesh()

Number libMesh::RBParametrizedFunction::lookup_preevaluated_value_on_mesh ( unsigned int  comp,
dof_id_type  elem_id,
unsigned int  qp 
) const
virtual

Look up the preevaluate values of the parametrized function for component comp, element elem_id, and quadrature point qp.

Definition at line 760 of file rb_parametrized_function.C.

763{
764 const std::vector<unsigned int> & indices_at_qps =
765 libmesh_map_find(mesh_to_preevaluated_values_map, elem_id);
766
767 libmesh_error_msg_if(qp >= indices_at_qps.size(), "Error: invalid qp");
768
769 unsigned int index = indices_at_qps[qp];
770 libmesh_error_msg_if(preevaluated_values.size() != 1, "Error: we expect only one parameter index");
771 libmesh_error_msg_if(index >= preevaluated_values[0].size(), "Error: invalid index");
772
773 return preevaluated_values[0][index][comp];
774}
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...

References mesh_to_preevaluated_values_map, and preevaluated_values.

Referenced by libMesh::RBEIMConstruction::initialize_parametrized_functions_in_training_set().

◆ node_evaluate()

std::vector< Number > libMesh::RBParametrizedFunction::node_evaluate ( const RBParameters mu,
const Point xyz,
dof_id_type  node_id,
boundary_id_type  boundary_id 
)
virtual

Same as evaluate() but for element nodes.

Definition at line 154 of file rb_parametrized_function.C.

158{
159 // This method should be overridden in subclasses, so we just give a not implemented error message here
160 libmesh_not_implemented();
161
162 return std::vector<Number>();
163}

Referenced by node_evaluate_comp(), and node_vectorized_evaluate().

◆ node_evaluate_comp()

Number libMesh::RBParametrizedFunction::node_evaluate_comp ( const RBParameters mu,
unsigned int  comp,
const Point xyz,
dof_id_type  node_id,
boundary_id_type  boundary_id 
)
virtual

Same as evaluate_comp() but for element nodes.

Definition at line 108 of file rb_parametrized_function.C.

113{
114 std::vector<Number> values = node_evaluate(mu, xyz, node_id, boundary_id);
115
116 libmesh_error_msg_if(comp >= values.size(), "Error: Invalid value of comp");
117
118 return values[comp];
119}
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.

References node_evaluate().

◆ node_vectorized_evaluate()

void libMesh::RBParametrizedFunction::node_vectorized_evaluate ( const std::vector< RBParameters > &  mus,
const VectorizedEvalInput v,
std::vector< std::vector< std::vector< Number > > > &  output 
)
virtual

Same as vectorized_evaluate() but on element nodes.

The base class implementation of this function loops over the input "mus" vector and calls node_evaluate() for each entry. The node_evaluate() function may be overridden in derived classes.

Definition at line 335 of file rb_parametrized_function.C.

338{
339 LOG_SCOPE("node_vectorized_evaluate()", "RBParametrizedFunction");
340
341 output.clear();
342 unsigned int n_points = v.all_xyz.size();
343
344 // The number of components returned by this RBParametrizedFunction
345 auto n_components = this->get_n_components();
346
347 // We first loop over all mus and all n_points, calling node_evaluate()
348 // for each and storing the results. It is easier to first
349 // pre-compute all the values before filling output, since, in the
350 // case of multi-sample RBParameters, the ordering of the loops is a
351 // bit complicated otherwise.
352 std::vector<std::vector<std::vector<Number>>> all_evals(mus.size());
353 for (auto mu_index : index_range(mus))
354 {
355 // Allocate enough space to store all points for the current mu
356 all_evals[mu_index].resize(n_points);
357 for (auto point_index : index_range(all_evals[mu_index]))
358 {
359 // Evaluate all samples for the current mu at the current interpolation point
360 all_evals[mu_index][point_index] =
361 this->node_evaluate(mus[mu_index],
362 v.all_xyz[point_index],
363 v.node_ids[point_index],
364 v.boundary_ids[point_index]);
365
366 // The vector returned by node_evaluate() should contain:
367 // n_components * mus[mu_index].n_samples()
368 // entries. That is, for multi-sample RBParameters objects,
369 // the vector will be packed with entries as follows:
370 // [sample0_component0, sample0_component1, ..., sample0_componentN,
371 // sample1_component0, sample1_component1, ..., sample1_componentN,
372 // ...
373 // sampleM_component0, sampleM_component1, ..., sampleM_componentN]
374 auto n_samples = mus[mu_index].n_samples();
375 auto received_data = all_evals[mu_index][point_index].size();
376 libmesh_error_msg_if(received_data != n_components * n_samples,
377 "Recieved " << received_data <<
378 " evaluated values but expected to receive " << n_components * n_samples);
379 }
380 }
381
382 // TODO: move this code for computing the total number of samples
383 // represented by a std::vector of RBParameters objects to a helper
384 // function.
385 unsigned int output_size = 0;
386 for (const auto & mu : mus)
387 output_size += mu.n_samples();
388
389 output.resize(output_size);
390
391 // We use traditional for-loops here (rather than range-based) so that we can declare and
392 // increment multiple loop counters all within the local scope of the for-loop.
393 for (auto [mu_index, output_index] = std::make_tuple(0u, 0u); mu_index < mus.size(); ++mu_index)
394 {
395 auto n_samples = mus[mu_index].n_samples();
396 for (auto mu_sample_idx = 0u; mu_sample_idx < n_samples; ++mu_sample_idx, ++output_index)
397 {
398 output[output_index].resize(n_points);
399 for (auto point_index : make_range(n_points))
400 {
401 output[output_index][point_index].resize(n_components);
402
403 for (auto comp : make_range(n_components))
404 output[output_index][point_index][comp] = all_evals[mu_index][point_index][n_components*mu_sample_idx + comp];
405 }
406 }
407 }
408}
virtual unsigned int get_n_components() const =0
Specify the number of components in this parametrized function.
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition int_range.h:153
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition int_range.h:176

References libMesh::VectorizedEvalInput::all_xyz, libMesh::VectorizedEvalInput::boundary_ids, get_n_components(), libMesh::index_range(), libMesh::make_range(), node_evaluate(), and libMesh::VectorizedEvalInput::node_ids.

Referenced by preevaluate_parametrized_function_on_mesh_nodes(), and libMesh::RBEIMEvaluation::rb_eim_solves().

◆ on_mesh_nodes()

bool libMesh::RBParametrizedFunction::on_mesh_nodes ( ) const

◆ on_mesh_sides()

bool libMesh::RBParametrizedFunction::on_mesh_sides ( ) const

◆ operator=() [1/2]

RBParametrizedFunction & libMesh::RBParametrizedFunction::operator= ( const RBParametrizedFunction )
default

◆ operator=() [2/2]

RBParametrizedFunction & libMesh::RBParametrizedFunction::operator= ( RBParametrizedFunction &&  )
default

◆ preevaluate_parametrized_function_cleanup()

void libMesh::RBParametrizedFunction::preevaluate_parametrized_function_cleanup ( )
virtual

Virtual function that performs cleanup after each "preevaluate parametrized function" evaluation.

This function is a no-op by default, but it can be overridden in subclasses in order to do necessary cleanup, such as clearing cached data.

Definition at line 828 of file rb_parametrized_function.C.

829{
830 // No-op by default
831}

Referenced by preevaluate_parametrized_function_on_mesh(), preevaluate_parametrized_function_on_mesh_nodes(), and preevaluate_parametrized_function_on_mesh_sides().

◆ preevaluate_parametrized_function_on_mesh()

void libMesh::RBParametrizedFunction::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 
)
virtual

Store the result of vectorized_evaluate.

This is helpful during EIM training, since we can pre-evaluate and store the parameterized function for each training sample. If requires_xyz_perturbations==false, then all_xyz_perturb will not be used.

Definition at line 410 of file rb_parametrized_function.C.

415{
417
418 unsigned int n_elems = all_xyz.size();
419 unsigned int n_points = 0;
420 for (const auto & xyz_pair : all_xyz)
421 {
422 const std::vector<Point> & xyz_vec = xyz_pair.second;
423 n_points += xyz_vec.size();
424 }
425
426 VectorizedEvalInput v;
427 v.all_xyz.resize(n_points);
428 v.elem_ids.resize(n_points);
429 v.qps.resize(n_points);
430 v.sbd_ids.resize(n_points);
431 v.all_xyz_perturb.resize(n_points);
432 v.phi_i_qp.resize(n_points);
433 v.elem_types.resize(n_points);
434
436 {
437 v.elem_id_to_local_index.clear();
438 v.JxW_all_qp.resize(n_elems);
439 v.phi_i_all_qp.resize(n_elems);
440 }
442 {
443 v.dxyzdxi_elem_center.resize(n_elems);
444 v.dxyzdeta_elem_center.resize(n_elems);
445 // At the time of writing, the quadrature order is only used in conjunction with element
446 // center data so we should not compute it elsewhere for now.
447 v.qrule_orders.resize(n_elems);
448 }
449
450 // Empty vector to be used when xyz perturbations are not required
451 std::vector<Point> empty_perturbs;
452
453 // In order to compute phi_i_qp, we initialize a FEMContext
454 FEMContext con(sys);
455 for (auto dim : con.elem_dimensions())
456 {
457 auto fe = con.get_element_fe(/*var=*/0, dim);
458 fe->get_JxW();
459 fe->get_phi();
460 fe->get_dxyzdxi();
461 fe->get_dxyzdeta();
462 }
463
464 unsigned int counter = 0;
465 unsigned int elem_counter = 0;
466 for (const auto & [elem_id, xyz_vec] : all_xyz)
467 {
468 subdomain_id_type subdomain_id = libmesh_map_find(sbd_ids, elem_id);
469
470 // The amount of data to be stored for each component
471 auto n_qp = xyz_vec.size();
472 mesh_to_preevaluated_values_map[elem_id].resize(n_qp);
473
474 // Also initialize phi in order to compute phi_i_qp
475 const Elem & elem_ref = sys.get_mesh().elem_ref(elem_id);
476 con.pre_fe_reinit(sys, &elem_ref);
477
478 auto elem_fe = con.get_element_fe(/*var=*/0, elem_ref.dim());
479 const std::vector<std::vector<Real>> & phi = elem_fe->get_phi();
480 const std::vector<Real> & JxW = elem_fe->get_JxW();
481 const auto & dxyzdxi = elem_fe->get_dxyzdxi();
482 const auto & dxyzdeta = elem_fe->get_dxyzdeta();
483
484 elem_fe->reinit(&elem_ref);
485
486 for (auto qp : index_range(xyz_vec))
487 {
488 mesh_to_preevaluated_values_map[elem_id][qp] = counter;
489
490 v.all_xyz[counter] = xyz_vec[qp];
491 v.elem_ids[counter] = elem_id;
492 v.qps[counter] = qp;
493 v.sbd_ids[counter] = subdomain_id;
494 v.elem_types[counter] = elem_ref.type();
495
496 v.phi_i_qp[counter].resize(phi.size());
497 for(auto i : index_range(phi))
498 v.phi_i_qp[counter][i] = phi[i][qp];
499
501 {
502 const auto & qps_and_perturbs =
503 libmesh_map_find(all_xyz_perturb, elem_id);
504 libmesh_error_msg_if(qp >= qps_and_perturbs.size(), "Error: Invalid qp");
505
506 v.all_xyz_perturb[counter] = qps_and_perturbs[qp];
507 }
508 else
509 {
510 v.all_xyz_perturb[counter] = empty_perturbs;
511 }
512
514 {
515 if (v.elem_id_to_local_index.count(elem_id) == 0)
516 {
517 // In this case we store data for all qps on this element
518 // at each point.
519 v.JxW_all_qp[elem_counter].resize(JxW.size());
520 for(auto i : index_range(JxW))
521 v.JxW_all_qp[elem_counter][i] = JxW[i];
522
523 v.phi_i_all_qp[elem_counter].resize(phi.size());
524 for(auto i : index_range(phi))
525 {
526 v.phi_i_all_qp[elem_counter][i].resize(phi[i].size());
527 for(auto j : index_range(phi[i]))
528 v.phi_i_all_qp[elem_counter][i][j] = phi[i][j];
529 }
530 v.elem_id_to_local_index[elem_id] = elem_counter;
531 }
532 }
533
534 counter++;
535 }
536
537 // Here we presume that if requires_all_elem_center_data is set to true
538 // then requires_all_elem_qp_data is also set to true so that elem_id_to_local_index entry
539 // for this elem has already been set.
541 {
542 // Get data derivatives at vertex average
543 std::vector<Point> nodes = { elem_ref.reference_elem()->vertex_average() };
544 elem_fe->reinit (&elem_ref, &nodes);
545 // Set qrule_order here to prevent calling getter multiple times.
546 Order qrule_order = con.get_element_qrule().get_order();
547
548 // We add qrule_order in this loop as it is used in conjunction with elem center
549 // quantities for now.
550 v.qrule_orders[elem_counter] = qrule_order;
551 Point dxyzdxi_pt, dxyzdeta_pt;
552 if (con.get_elem_dim()>0)
553 dxyzdxi_pt = dxyzdxi[0];
554 if (con.get_elem_dim()>1)
555 dxyzdeta_pt = dxyzdeta[0];
556 // Here we do an implicit conversion from RealGradient which is a VectorValue<Real>
557 // which in turn is a TypeVector<T> to a Point which is a TypeVector<Real>.
558 // They are essentially the same thing. This helps us limiting the number of includes
559 // in serialization and deserialization as RealGradient is a typedef and we cannot
560 // forward declare typedefs. As a result we leverage the fact that point.h is already
561 // included in most places we need RealGradient.
562 v.dxyzdxi_elem_center[elem_counter] = dxyzdxi_pt;
563 v.dxyzdeta_elem_center[elem_counter] = dxyzdeta_pt;
564 }
565 elem_counter++;
566 }
567
568 std::vector<RBParameters> mus {mu};
570
572}
unsigned int dim
virtual void preevaluate_parametrized_function_cleanup()
Virtual function that performs cleanup after each "preevaluate parametrized function" evaluation.
virtual void vectorized_evaluate(const std::vector< RBParameters > &mus, const VectorizedEvalInput &v, std::vector< std::vector< std::vector< Number > > > &output)
Vectorized version of evaluate.
TestClass subdomain_id_type
Based on the 4-byte comment warning above, this probably doesn't work with exodusII at all....
Definition id_types.h:43

References libMesh::VectorizedEvalInput::all_xyz, libMesh::VectorizedEvalInput::all_xyz_perturb, dim, libMesh::Elem::dim(), libMesh::VectorizedEvalInput::dxyzdeta_elem_center, libMesh::VectorizedEvalInput::dxyzdxi_elem_center, libMesh::FEMContext::elem_dimensions(), libMesh::VectorizedEvalInput::elem_id_to_local_index, libMesh::VectorizedEvalInput::elem_ids, libMesh::MeshBase::elem_ref(), libMesh::VectorizedEvalInput::elem_types, libMesh::FEMContext::get_elem_dim(), libMesh::FEMContext::get_element_fe(), libMesh::FEMContext::get_element_qrule(), libMesh::System::get_mesh(), libMesh::QBase::get_order(), libMesh::index_range(), libMesh::VectorizedEvalInput::JxW_all_qp, mesh_to_preevaluated_values_map, libMesh::VectorizedEvalInput::phi_i_all_qp, libMesh::VectorizedEvalInput::phi_i_qp, libMesh::FEMContext::pre_fe_reinit(), preevaluate_parametrized_function_cleanup(), preevaluated_values, libMesh::VectorizedEvalInput::qps, libMesh::VectorizedEvalInput::qrule_orders, libMesh::Elem::reference_elem(), requires_all_elem_center_data, requires_all_elem_qp_data, requires_xyz_perturbations, libMesh::VectorizedEvalInput::sbd_ids, libMesh::Elem::type(), vectorized_evaluate(), and libMesh::Elem::vertex_average().

Referenced by libMesh::RBEIMConstruction::initialize_parametrized_functions_in_training_set().

◆ preevaluate_parametrized_function_on_mesh_nodes()

void libMesh::RBParametrizedFunction::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 
)
virtual

Same as preevaluate_parametrized_function_on_mesh() except for mesh nodes.

Definition at line 723 of file rb_parametrized_function.C.

727{
729
730 unsigned int n_points = all_xyz.size();
731
732 VectorizedEvalInput v;
733 v.all_xyz.resize(n_points);
734 v.node_ids.resize(n_points);
735 v.boundary_ids.resize(n_points);
736
737 // Empty vector to be used when xyz perturbations are not required
738 std::vector<Point> empty_perturbs;
739
740 unsigned int counter = 0;
741 for (const auto & [node_id, p] : all_xyz)
742 {
743 boundary_id_type boundary_id = libmesh_map_find(node_boundary_ids, node_id);
744
745 mesh_to_preevaluated_node_values_map[node_id] = counter;
746
747 v.all_xyz[counter] = p;
748 v.node_ids[counter] = node_id;
749 v.boundary_ids[counter] = boundary_id;
750
751 counter++;
752 }
753
754 std::vector<RBParameters> mus {mu};
756
758}
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.
int8_t boundary_id_type
Definition id_types.h:51

References libMesh::VectorizedEvalInput::all_xyz, libMesh::VectorizedEvalInput::boundary_ids, mesh_to_preevaluated_node_values_map, libMesh::VectorizedEvalInput::node_ids, node_vectorized_evaluate(), preevaluate_parametrized_function_cleanup(), and preevaluated_values.

Referenced by libMesh::RBEIMConstruction::initialize_parametrized_functions_in_training_set().

◆ preevaluate_parametrized_function_on_mesh_sides()

void libMesh::RBParametrizedFunction::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 
)
virtual

Same as preevaluate_parametrized_function_on_mesh() except for mesh sides.

Definition at line 574 of file rb_parametrized_function.C.

581{
583
584 unsigned int n_points = 0;
585 for (const auto & xyz_pair : side_all_xyz)
586 {
587 const std::vector<Point> & xyz_vec = xyz_pair.second;
588 n_points += xyz_vec.size();
589 }
590
591 VectorizedEvalInput v;
592 v.all_xyz.resize(n_points);
593 v.elem_ids.resize(n_points);
594 v.side_indices.resize(n_points);
595 v.qps.resize(n_points);
596 v.sbd_ids.resize(n_points);
597 v.boundary_ids.resize(n_points);
598 v.all_xyz_perturb.resize(n_points);
599 v.phi_i_qp.resize(n_points);
600
601 // Empty vector to be used when xyz perturbations are not required
602 std::vector<Point> empty_perturbs;
603
604 // In order to compute phi_i_qp, we initialize a FEMContext
605 FEMContext con(sys);
606 for (auto dim : con.elem_dimensions())
607 {
608 auto fe = con.get_element_fe(/*var=*/0, dim);
609 fe->get_phi();
610
611 auto side_fe = con.get_side_fe(/*var=*/0, dim);
612 side_fe->get_phi();
613 }
614
615 unsigned int counter = 0;
616 for (const auto & xyz_pair : side_all_xyz)
617 {
618 auto elem_side_pair = xyz_pair.first;
619 dof_id_type elem_id = elem_side_pair.first;
620 unsigned int side_index = elem_side_pair.second;
621
622 const std::vector<Point> & xyz_vec = xyz_pair.second;
623
624 subdomain_id_type subdomain_id = libmesh_map_find(sbd_ids, elem_side_pair);
625 boundary_id_type boundary_id = libmesh_map_find(side_boundary_ids, elem_side_pair);
626 unsigned int side_type = libmesh_map_find(side_types, elem_side_pair);
627
628 // The amount of data to be stored for each component
629 auto n_qp = xyz_vec.size();
630 mesh_to_preevaluated_side_values_map[elem_side_pair].resize(n_qp);
631
632 const Elem & elem_ref = sys.get_mesh().elem_ref(elem_id);
633 con.pre_fe_reinit(sys, &elem_ref);
634
635 // side_type == 0 --> standard side
636 // side_type == 1 --> shellface
637 if (side_type == 0)
638 {
639 std::unique_ptr<const Elem> elem_side;
640 elem_ref.build_side_ptr(elem_side, side_index);
641
642 auto side_fe = con.get_side_fe(/*var=*/0, elem_ref.dim());
643 side_fe->reinit(&elem_ref, side_index);
644
645 const std::vector<std::vector<Real>> & phi = side_fe->get_phi();
646 for (auto qp : index_range(xyz_vec))
647 {
648 mesh_to_preevaluated_side_values_map[elem_side_pair][qp] = counter;
649
650 v.all_xyz[counter] = xyz_vec[qp];
651 v.elem_ids[counter] = elem_side_pair.first;
652 v.side_indices[counter] = elem_side_pair.second;
653 v.qps[counter] = qp;
654 v.sbd_ids[counter] = subdomain_id;
655 v.boundary_ids[counter] = boundary_id;
656
657 v.phi_i_qp[counter].resize(phi.size());
658 for(auto i : index_range(phi))
659 v.phi_i_qp[counter][i] = phi[i][qp];
660
662 {
663 const auto & qps_and_perturbs =
664 libmesh_map_find(side_all_xyz_perturb, elem_side_pair);
665 libmesh_error_msg_if(qp >= qps_and_perturbs.size(), "Error: Invalid qp");
666
667 v.all_xyz_perturb[counter] = qps_and_perturbs[qp];
668 }
669 else
670 {
671 v.all_xyz_perturb[counter] = empty_perturbs;
672 }
673 counter++;
674 }
675 }
676 else if (side_type == 1)
677 {
678 auto elem_fe = con.get_element_fe(/*var=*/0, elem_ref.dim());
679 const std::vector<std::vector<Real>> & phi = elem_fe->get_phi();
680
681 elem_fe->reinit(&elem_ref);
682
683 for (auto qp : index_range(xyz_vec))
684 {
685 mesh_to_preevaluated_side_values_map[elem_side_pair][qp] = counter;
686
687 v.all_xyz[counter] = xyz_vec[qp];
688 v.elem_ids[counter] = elem_side_pair.first;
689 v.side_indices[counter] = elem_side_pair.second;
690 v.qps[counter] = qp;
691 v.sbd_ids[counter] = subdomain_id;
692 v.boundary_ids[counter] = boundary_id;
693
694 v.phi_i_qp[counter].resize(phi.size());
695 for(auto i : index_range(phi))
696 v.phi_i_qp[counter][i] = phi[i][qp];
697
699 {
700 const auto & qps_and_perturbs =
701 libmesh_map_find(side_all_xyz_perturb, elem_side_pair);
702 libmesh_error_msg_if(qp >= qps_and_perturbs.size(), "Error: Invalid qp");
703
704 v.all_xyz_perturb[counter] = qps_and_perturbs[qp];
705 }
706 else
707 {
708 v.all_xyz_perturb[counter] = empty_perturbs;
709 }
710 counter++;
711 }
712 }
713 else
714 libmesh_error_msg ("Unrecognized side_type: " << side_type);
715 }
716
717 std::vector<RBParameters> mus {mu};
719
721}
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.
uint8_t dof_id_type
Definition id_types.h:67

References libMesh::VectorizedEvalInput::all_xyz, libMesh::VectorizedEvalInput::all_xyz_perturb, libMesh::VectorizedEvalInput::boundary_ids, libMesh::Elem::build_side_ptr(), dim, libMesh::Elem::dim(), libMesh::FEMContext::elem_dimensions(), libMesh::VectorizedEvalInput::elem_ids, libMesh::MeshBase::elem_ref(), libMesh::FEMContext::get_element_fe(), libMesh::System::get_mesh(), libMesh::FEMContext::get_side_fe(), libMesh::index_range(), mesh_to_preevaluated_side_values_map, libMesh::VectorizedEvalInput::phi_i_qp, libMesh::FEMContext::pre_fe_reinit(), preevaluate_parametrized_function_cleanup(), preevaluated_values, libMesh::VectorizedEvalInput::qps, requires_xyz_perturbations, libMesh::VectorizedEvalInput::sbd_ids, libMesh::VectorizedEvalInput::side_indices, and side_vectorized_evaluate().

Referenced by libMesh::RBEIMConstruction::initialize_parametrized_functions_in_training_set().

◆ set_parametrized_function_boundary_ids()

void libMesh::RBParametrizedFunction::set_parametrized_function_boundary_ids ( const std::set< boundary_id_type > &  boundary_ids,
bool  is_nodal_boundary 
)

Definition at line 857 of file rb_parametrized_function.C.

858{
860 _is_nodal_boundary = is_nodal_boundary;
861}

References _is_nodal_boundary, and _parametrized_function_boundary_ids.

◆ side_evaluate()

std::vector< Number > libMesh::RBParametrizedFunction::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 
)
virtual

Same as evaluate() but for element sides.

Definition at line 137 of file rb_parametrized_function.C.

146{
147 // This method should be overridden in subclasses, so we just give a not implemented error message here
148 libmesh_not_implemented();
149
150 return std::vector<Number>();
151}

Referenced by side_evaluate_comp(), and side_vectorized_evaluate().

◆ side_evaluate_comp()

Number libMesh::RBParametrizedFunction::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 
)
virtual

Same as evaluate_comp() but for element sides.

Definition at line 89 of file rb_parametrized_function.C.

99{
100 std::vector<Number> values = side_evaluate(mu, xyz, elem_id, side_index, qp, subdomain_id, boundary_id, xyz_perturb, phi_i_qp);
101
102 libmesh_error_msg_if(comp >= values.size(), "Error: Invalid value of comp");
103
104 return values[comp];
105}
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.

References side_evaluate().

◆ side_vectorized_evaluate()

void libMesh::RBParametrizedFunction::side_vectorized_evaluate ( const std::vector< RBParameters > &  mus,
const VectorizedEvalInput v,
std::vector< std::vector< std::vector< Number > > > &  output 
)
virtual

Same as vectorized_evaluate() but on element sides.

The base class implementation of this function loops over the input "mus" vector and calls side_evaluate() for each entry. The side_evaluate() function may be overridden in derived classes.

Definition at line 249 of file rb_parametrized_function.C.

252{
253 LOG_SCOPE("side_vectorized_evaluate()", "RBParametrizedFunction");
254
255 output.clear();
256 unsigned int n_points = v.all_xyz.size();
257
258 libmesh_error_msg_if(v.sbd_ids.size() != n_points, "Error: invalid vector sizes");
259 libmesh_error_msg_if(requires_xyz_perturbations && (v.all_xyz_perturb.size() != n_points), "Error: invalid vector sizes");
260
261 // Dummy vector to be used when xyz perturbations are not required
262 std::vector<Point> empty_perturbs;
263
264 // The number of components returned by this RBParametrizedFunction
265 auto n_components = this->get_n_components();
266
267 // We first loop over all mus and all n_points, calling side_evaluate()
268 // for each and storing the results. It is easier to first
269 // pre-compute all the values before filling output, since, in the
270 // case of multi-sample RBParameters, the ordering of the loops is a
271 // bit complicated otherwise.
272 std::vector<std::vector<std::vector<Number>>> all_evals(mus.size());
273 for (auto mu_index : index_range(mus))
274 {
275 // Allocate enough space to store all points for the current mu
276 all_evals[mu_index].resize(n_points);
277 for (auto point_index : index_range(all_evals[mu_index]))
278 {
279 // Evaluate all samples for the current mu at the current interpolation point
280 all_evals[mu_index][point_index] =
281 this->side_evaluate(mus[mu_index],
282 v.all_xyz[point_index],
283 v.elem_ids[point_index],
284 v.side_indices[point_index],
285 v.qps[point_index],
286 v.sbd_ids[point_index],
287 v.boundary_ids[point_index],
288 requires_xyz_perturbations ? v.all_xyz_perturb[point_index] : empty_perturbs,
289 v.phi_i_qp[point_index]);
290
291 // The vector returned by side_evaluate() should contain:
292 // n_components * mus[mu_index].n_samples()
293 // entries. That is, for multi-sample RBParameters objects,
294 // the vector will be packed with entries as follows:
295 // [sample0_component0, sample0_component1, ..., sample0_componentN,
296 // sample1_component0, sample1_component1, ..., sample1_componentN,
297 // ...
298 // sampleM_component0, sampleM_component1, ..., sampleM_componentN]
299 auto n_samples = mus[mu_index].n_samples();
300 auto received_data = all_evals[mu_index][point_index].size();
301 libmesh_error_msg_if(received_data != n_components * n_samples,
302 "Recieved " << received_data <<
303 " evaluated values but expected to receive " << n_components * n_samples);
304 }
305 }
306
307 // TODO: move this code for computing the total number of samples
308 // represented by a std::vector of RBParameters objects to a helper
309 // function.
310 unsigned int output_size = 0;
311 for (const auto & mu : mus)
312 output_size += mu.n_samples();
313
314 output.resize(output_size);
315
316 // We use traditional for-loops here (rather than range-based) so that we can declare and
317 // increment multiple loop counters all within the local scope of the for-loop.
318 for (auto [mu_index, output_index] = std::make_tuple(0u, 0u); mu_index < mus.size(); ++mu_index)
319 {
320 auto n_samples = mus[mu_index].n_samples();
321 for (auto mu_sample_idx = 0u; mu_sample_idx < n_samples; ++mu_sample_idx, ++output_index)
322 {
323 output[output_index].resize(n_points);
324 for (auto point_index : make_range(n_points))
325 {
326 output[output_index][point_index].resize(n_components);
327
328 for (auto comp : make_range(n_components))
329 output[output_index][point_index][comp] = all_evals[mu_index][point_index][n_components*mu_sample_idx + comp];
330 }
331 }
332 }
333}

References libMesh::VectorizedEvalInput::all_xyz, libMesh::VectorizedEvalInput::all_xyz_perturb, libMesh::VectorizedEvalInput::boundary_ids, libMesh::VectorizedEvalInput::elem_ids, get_n_components(), libMesh::index_range(), libMesh::make_range(), libMesh::VectorizedEvalInput::phi_i_qp, libMesh::VectorizedEvalInput::qps, requires_xyz_perturbations, libMesh::VectorizedEvalInput::sbd_ids, side_evaluate(), and libMesh::VectorizedEvalInput::side_indices.

Referenced by preevaluate_parametrized_function_on_mesh_sides(), and libMesh::RBEIMEvaluation::rb_eim_solves().

◆ vectorized_evaluate()

void libMesh::RBParametrizedFunction::vectorized_evaluate ( const std::vector< RBParameters > &  mus,
const VectorizedEvalInput v,
std::vector< std::vector< std::vector< Number > > > &  output 
)
virtual

Vectorized version of evaluate.

If requires_xyz_perturbations==false, then all_xyz_perturb will not be used.

The base class implementation of this function loops over the input "mus" vector and calls evaluate() for each entry. The evaluate() function may be overridden in derived classes.

Definition at line 165 of file rb_parametrized_function.C.

168{
169 LOG_SCOPE("vectorized_evaluate()", "RBParametrizedFunction");
170
171 output.clear();
172 unsigned int n_points = v.all_xyz.size();
173
174 libmesh_error_msg_if(v.sbd_ids.size() != n_points, "Error: invalid vector sizes");
175 libmesh_error_msg_if(requires_xyz_perturbations && (v.all_xyz_perturb.size() != n_points), "Error: invalid vector sizes");
176
177 // Dummy vector to be used when xyz perturbations are not required
178 std::vector<Point> empty_perturbs;
179
180 // The number of components returned by this RBParametrizedFunction
181 auto n_components = this->get_n_components();
182
183 // We first loop over all mus and all n_points, calling evaluate()
184 // for each and storing the results. It is easier to first
185 // pre-compute all the values before filling output, since, in the
186 // case of multi-sample RBParameters, the ordering of the loops is a
187 // bit complicated otherwise.
188 std::vector<std::vector<std::vector<Number>>> all_evals(mus.size());
189 for (auto mu_index : index_range(mus))
190 {
191 // Allocate enough space to store all points for the current mu
192 all_evals[mu_index].resize(n_points);
193 for (auto point_index : index_range(all_evals[mu_index]))
194 {
195 // Evaluate all samples for the current mu at the current interpolation point
196 all_evals[mu_index][point_index] =
197 this->evaluate(mus[mu_index],
198 v.all_xyz[point_index],
199 v.elem_ids[point_index],
200 v.qps[point_index],
201 v.sbd_ids[point_index],
202 requires_xyz_perturbations ? v.all_xyz_perturb[point_index] : empty_perturbs,
203 v.phi_i_qp[point_index]);
204
205 // The vector returned by evaluate() should contain:
206 // n_components * mus[mu_index].n_samples()
207 // entries. That is, for multi-sample RBParameters objects,
208 // the vector will be packed with entries as follows:
209 // [sample0_component0, sample0_component1, ..., sample0_componentN,
210 // sample1_component0, sample1_component1, ..., sample1_componentN,
211 // ...
212 // sampleM_component0, sampleM_component1, ..., sampleM_componentN]
213 auto n_samples = mus[mu_index].n_samples();
214 auto received_data = all_evals[mu_index][point_index].size();
215 libmesh_error_msg_if(received_data != n_components * n_samples,
216 "Recieved " << received_data <<
217 " evaluated values but expected to receive " << n_components * n_samples);
218 }
219 }
220
221 // TODO: move this code for computing the total number of samples
222 // represented by a std::vector of RBParameters objects to a helper
223 // function.
224 unsigned int output_size = 0;
225 for (const auto & mu : mus)
226 output_size += mu.n_samples();
227
228 output.resize(output_size);
229
230 // We use traditional for-loops here (rather than range-based) so that we can declare and
231 // increment multiple loop counters all within the local scope of the for-loop.
232 for (auto [mu_index, output_index] = std::make_tuple(0u, 0u); mu_index < mus.size(); ++mu_index)
233 {
234 auto n_samples = mus[mu_index].n_samples();
235 for (auto mu_sample_idx = 0u; mu_sample_idx < n_samples; ++mu_sample_idx, ++output_index)
236 {
237 output[output_index].resize(n_points);
238 for (auto point_index : make_range(n_points))
239 {
240 output[output_index][point_index].resize(n_components);
241
242 for (auto comp : make_range(n_components))
243 output[output_index][point_index][comp] = all_evals[mu_index][point_index][n_components*mu_sample_idx + comp];
244 }
245 }
246 }
247}

References libMesh::VectorizedEvalInput::all_xyz, libMesh::VectorizedEvalInput::all_xyz_perturb, libMesh::VectorizedEvalInput::elem_ids, evaluate(), get_n_components(), libMesh::index_range(), libMesh::make_range(), libMesh::VectorizedEvalInput::phi_i_qp, libMesh::VectorizedEvalInput::qps, requires_xyz_perturbations, and libMesh::VectorizedEvalInput::sbd_ids.

Referenced by preevaluate_parametrized_function_on_mesh(), and libMesh::RBEIMEvaluation::rb_eim_solves().

Member Data Documentation

◆ _is_nodal_boundary

bool libMesh::RBParametrizedFunction::_is_nodal_boundary
protected

In the case that _parametrized_function_boundary_ids is not empty, then this parametrized function is defined on a mesh boundary.

This boolean indicates if the mesh boundary under consideration is a set of sides, or a set of nodes.

Definition at line 492 of file rb_parametrized_function.h.

Referenced by on_mesh_nodes(), on_mesh_sides(), and set_parametrized_function_boundary_ids().

◆ _parameter_independent_data

std::map<std::string, std::map<subdomain_id_type, Number> > libMesh::RBParametrizedFunction::_parameter_independent_data
protected

In some cases we need to store parameter-independent data which is related to this function but since it is parameter-indepedent should not be returned as part of evaluate().

We index this data by "property name" --> subdomain_id --> value.

Definition at line 479 of file rb_parametrized_function.h.

Referenced by get_parameter_independent_data().

◆ _parametrized_function_boundary_ids

std::set<boundary_id_type> libMesh::RBParametrizedFunction::_parametrized_function_boundary_ids
protected

In the case of an RBParametrizedFunction defined on element sides, this defines the set of boundary IDs that the function is defined on.

Definition at line 485 of file rb_parametrized_function.h.

Referenced by get_parametrized_function_boundary_ids(), and set_parametrized_function_boundary_ids().

◆ _rb_property_map

std::unordered_map<std::string, std::set<dof_id_type> > libMesh::RBParametrizedFunction::_rb_property_map
protected

Generic property map used to store data during mesh pre-evaluation.

It should be initialized from a vectorized_evaluate() call during the mesh pre-evaluation. Then this RBParametrizedFunction rb_property_map is used to fill the RBEIMEvaluation VectorizedEvalInput rb_property_map with the same properties but interpolation point data only instead of the entire mesh.

Definition at line 500 of file rb_parametrized_function.h.

Referenced by add_rb_property_map_entry(), and get_rb_property_map().

◆ fd_delta

Real libMesh::RBParametrizedFunction::fd_delta

The finite difference step size in the case that this function in the case that this function uses finite differencing.

Definition at line 468 of file rb_parametrized_function.h.

Referenced by libMesh::RBEIMConstruction::initialize_qp_data().

◆ is_lookup_table

bool libMesh::RBParametrizedFunction::is_lookup_table

Boolean to indicate if this parametrized function is defined based on a lookup table or not.

If it is defined based on a lookup table, then the evaluation functions will access a discrete parameter to determine the index to lookup.

Definition at line 456 of file rb_parametrized_function.h.

Referenced by libMesh::RBDataSerialization::add_rb_eim_evaluation_data_to_builder(), libMesh::RBEIMConstruction::initialize_parametrized_functions_in_training_set(), libMesh::RBDataDeserialization::load_rb_eim_evaluation_data(), and libMesh::RBEIMConstruction::train_eim_approximation_with_greedy().

◆ lookup_table_param_name

std::string libMesh::RBParametrizedFunction::lookup_table_param_name

If this is a lookup table, then lookup_table_param_name specifies the parameter that is used to index into the lookup table.

Definition at line 462 of file rb_parametrized_function.h.

Referenced by libMesh::RBEIMEvaluation::rb_eim_solves(), and libMesh::RBEIMConstruction::set_rb_construction_parameters().

◆ mesh_to_preevaluated_node_values_map

std::unordered_map<dof_id_type, unsigned int> libMesh::RBParametrizedFunction::mesh_to_preevaluated_node_values_map

Indexing into preevaluated_values for the case where the preevaluated values were obtained from evaluations at elements/quadrature points on a mesh.

The indexing here is: node_id --> point_index

Definition at line 427 of file rb_parametrized_function.h.

Referenced by lookup_preevaluated_node_value_on_mesh(), and preevaluate_parametrized_function_on_mesh_nodes().

◆ mesh_to_preevaluated_side_values_map

std::map<std::pair<dof_id_type,unsigned int>, std::vector<unsigned int> > libMesh::RBParametrizedFunction::mesh_to_preevaluated_side_values_map

Similar to the above except this map stores the data on element sides.

The indexing here is: (elem_id,side index) --> qp --> point_index

Definition at line 419 of file rb_parametrized_function.h.

Referenced by lookup_preevaluated_side_value_on_mesh(), and preevaluate_parametrized_function_on_mesh_sides().

◆ mesh_to_preevaluated_values_map

std::unordered_map<dof_id_type, std::vector<unsigned int> > libMesh::RBParametrizedFunction::mesh_to_preevaluated_values_map

Indexing into preevaluated_values for the case where the preevaluated values were obtained from evaluations at elements/quadrature points on a mesh.

The indexing here is: elem_id --> qp --> point_index Then preevaluated_values[0][point_index] provides the vector of component values at that point.

Definition at line 412 of file rb_parametrized_function.h.

Referenced by lookup_preevaluated_value_on_mesh(), and preevaluate_parametrized_function_on_mesh().

◆ preevaluated_values

std::vector<std::vector<std::vector<Number> > > libMesh::RBParametrizedFunction::preevaluated_values

◆ requires_all_elem_center_data

bool libMesh::RBParametrizedFunction::requires_all_elem_center_data

Boolean to indicate whether this parametrized function requires data from the center on the current element.

Definition at line 449 of file rb_parametrized_function.h.

Referenced by preevaluate_parametrized_function_on_mesh().

◆ requires_all_elem_qp_data

bool libMesh::RBParametrizedFunction::requires_all_elem_qp_data

Boolean to indicate whether this parametrized function requires data from all qps on the current element at each qp location.

This can be necessary in certain cases, e.g. when the parametrized function depends on "element average" quantities.

Definition at line 443 of file rb_parametrized_function.h.

Referenced by preevaluate_parametrized_function_on_mesh().

◆ requires_xyz_perturbations

bool libMesh::RBParametrizedFunction::requires_xyz_perturbations

Boolean to indicate whether this parametrized function requires xyz perturbations in order to evaluate function values.

An example of where perturbations are required is when the parametrized function is based on finite difference approximations to derivatives.

Definition at line 435 of file rb_parametrized_function.h.

Referenced by libMesh::RBEIMConstruction::initialize_qp_data(), preevaluate_parametrized_function_on_mesh(), preevaluate_parametrized_function_on_mesh_sides(), side_vectorized_evaluate(), and vectorized_evaluate().


The documentation for this class was generated from the following files: