libMesh
assembly.h
Go to the documentation of this file.
1 #ifndef ASSEMBLY_H
2 #define ASSEMBLY_H
3 
4 // libMesh includes
5 #include "libmesh/libmesh.h"
6 #include "libmesh/mesh.h"
7 #include "libmesh/equation_systems.h"
8 #include "libmesh/fe.h"
9 #include "libmesh/quadrature.h"
10 #include "libmesh/dof_map.h"
11 #include "libmesh/dense_matrix.h"
12 #include "libmesh/dense_vector.h"
13 #include "libmesh/fe_interface.h"
14 #include "libmesh/elem.h"
15 
16 // rbOOmit includes
17 #include "libmesh/rb_assembly_expansion.h"
18 #include "libmesh/rb_eim_theta.h"
19 #include "libmesh/rb_parametrized_function.h"
20 
21 // Bring in bits from the libMesh namespace.
22 // Just the bits we're using, since this is a header.
25 using libMesh::Number;
26 using libMesh::Point;
32 using libMesh::RBTheta;
34 using libMesh::Real;
36 using libMesh::Elem;
37 using libMesh::FEBase;
38 
40 {
41  virtual Number evaluate(const RBParameters & mu,
42  const Point & p,
43  const Elem &)
44  {
45  Real center_x = mu.get_value("center_x");
46  Real center_y = mu.get_value("center_y");
47  return exp(-2.*(pow(center_x-p(0),2.) + pow(center_y-p(1),2.)));
48  }
49 };
50 
51 // Expansion of the PDE operator
52 struct ThetaA0 : RBTheta { virtual Number evaluate(const RBParameters &) { return 0.05; } };
53 
54 struct A0 : ElemAssembly
55 {
56  // Assemble the Laplacian operator
57  virtual void interior_assembly(FEMContext & c)
58  {
59  const unsigned int u_var = 0;
60 
61  FEBase * elem_fe = nullptr;
62  c.get_element_fe(u_var, elem_fe);
63 
64  const std::vector<Real> & JxW = elem_fe->get_JxW();
65 
66  // The velocity shape function gradients at interior
67  // quadrature points.
68  const std::vector<std::vector<RealGradient>> & dphi = elem_fe->get_dphi();
69 
70  // The number of local degrees of freedom in each variable
71  const unsigned int n_u_dofs = c.get_dof_indices(u_var).size();
72 
73  // Now we will build the affine operator
74  unsigned int n_qpoints = c.get_element_qrule().n_points();
75 
76  for (unsigned int qp=0; qp != n_qpoints; qp++)
77  for (unsigned int i=0; i != n_u_dofs; i++)
78  for (unsigned int j=0; j != n_u_dofs; j++)
79  c.get_elem_jacobian()(i,j) += JxW[qp] * dphi[j][qp]*dphi[i][qp];
80  }
81 };
82 
83 
85 {
86  // Use the L2 norm to find the best fit
87  virtual void interior_assembly(FEMContext & c)
88  {
89  const unsigned int u_var = 0;
90 
91  FEBase * elem_fe = nullptr;
92  c.get_element_fe(u_var, elem_fe);
93 
94  const std::vector<Real> & JxW = elem_fe->get_JxW();
95 
96  const std::vector<std::vector<Real>> & phi = elem_fe->get_phi();
97 
98  const unsigned int n_u_dofs = c.get_dof_indices(u_var).size();
99 
100  unsigned int n_qpoints = c.get_element_qrule().n_points();
101 
102  for (unsigned int qp=0; qp != n_qpoints; qp++)
103  for (unsigned int i=0; i != n_u_dofs; i++)
104  for (unsigned int j=0; j != n_u_dofs; j++)
105  c.get_elem_jacobian()(i,j) += JxW[qp] * phi[j][qp]*phi[i][qp];
106  }
107 };
108 
110 {
111  EIM_F(RBEIMConstruction & rb_eim_con_in,
112  unsigned int basis_function_index_in) :
113  RBEIMAssembly(rb_eim_con_in,
114  basis_function_index_in)
115  {}
116 
117  virtual void interior_assembly(FEMContext & c)
118  {
119  // PDE variable number
120  const unsigned int u_var = 0;
121 
122  FEBase * elem_fe = nullptr;
123  c.get_element_fe(u_var, elem_fe);
124 
125  // EIM variable number
126  const unsigned int eim_var = 0;
127 
128  const std::vector<Real> & JxW = elem_fe->get_JxW();
129 
130  const std::vector<std::vector<Real>> & phi = elem_fe->get_phi();
131 
132  // The number of local degrees of freedom in each variable
133  const unsigned int n_u_dofs = c.get_dof_indices(u_var).size();
134 
135  std::vector<Number> eim_values;
136  evaluate_basis_function(eim_var,
137  c.get_elem(),
139  eim_values);
140 
141  for (unsigned int qp=0; qp != c.get_element_qrule().n_points(); qp++)
142  for (unsigned int i=0; i != n_u_dofs; i++)
143  c.get_elem_residual()(i) += JxW[qp] * (eim_values[qp]*phi[i][qp]);
144  }
145 };
146 
147 // Define an RBThetaExpansion class for this PDE
149 {
154  {
156  }
157 
158  // The RBTheta member variables
160 };
161 
162 // Define an RBAssemblyExpansion class for this PDE
164 {
169  {
171  }
172 
173  // A0 assembly object
175 };
176 
177 #endif
libMesh::Number
Real Number
Definition: libmesh_common.h:195
libMesh::DiffContext::get_elem_residual
const DenseVector< Number > & get_elem_residual() const
Const accessor for element residual.
Definition: diff_context.h:249
libMesh::FEMContext::get_element_qrule
const QBase & get_element_qrule() const
Accessor for element interior quadrature rule for the dimension of the current _elem.
Definition: fem_context.h:790
A0::interior_assembly
virtual void interior_assembly(FEMContext &c)
Perform the element interior assembly.
Definition: assembly.h:57
libMesh::DiffContext::get_dof_indices
const std::vector< dof_id_type > & get_dof_indices() const
Accessor for element dof indices.
Definition: diff_context.h:367
libMesh::QBase::n_points
unsigned int n_points() const
Definition: quadrature.h:126
libMesh::RealGradient
RealVectorValue RealGradient
Definition: hp_coarsentest.h:49
EIM_F::interior_assembly
virtual void interior_assembly(FEMContext &c)
Perform the element interior assembly.
Definition: assembly.h:117
libMesh::FEMContext::get_elem
const Elem & get_elem() const
Accessor for current Elem object.
Definition: fem_context.h:896
libMesh::RBParameters
This class is part of the rbOOmit framework.
Definition: rb_parameters.h:42
ShiftedGaussian::evaluate
virtual Number evaluate(const RBParameters &mu, const Point &p, const Elem &)
Evaluate this parametrized function for the parameter value mu at the point p.
Definition: assembly.h:41
EimTestRBThetaExpansion::EimTestRBThetaExpansion
EimTestRBThetaExpansion()
Constructor.
Definition: assembly.h:153
libMesh::RBEIMAssembly
This class provides functionality required to define an assembly object that arises from an "Empirica...
Definition: rb_eim_assembly.h:49
EimTestRBAssemblyExpansion::EimTestRBAssemblyExpansion
EimTestRBAssemblyExpansion()
Constructor.
Definition: assembly.h:168
EIM_IP_assembly::interior_assembly
virtual void interior_assembly(FEMContext &c)
Perform the element interior assembly.
Definition: assembly.h:87
libMesh::RBAssemblyExpansion
This class stores the set of ElemAssembly functor objects that define the "parameter-independent expa...
Definition: rb_assembly_expansion.h:44
EIM_F
Definition: assembly.h:109
libMesh::FEBase
FEGenericBase< Real > FEBase
Definition: exact_error_estimator.h:39
libMesh::QBase::get_points
const std::vector< Point > & get_points() const
Definition: quadrature.h:141
EimTestRBThetaExpansion
Definition: assembly.h:148
libMesh::Point
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
libMesh::RBParametrizedFunction
A simple functor class that provides a RBParameter-dependent function.
Definition: rb_parametrized_function.h:42
libMesh::RBAssemblyExpansion::attach_A_assembly
void attach_A_assembly(ElemAssembly *Aq_assembly)
Attach ElemAssembly object for the left-hand side (both interior and boundary assembly).
Definition: rb_assembly_expansion.C:131
std::pow
double pow(double a, int b)
Definition: libmesh_augment_std_namespace.h:58
ThetaA0::evaluate
virtual Number evaluate(const RBParameters &)
Evaluate the functor object for the given parameter.
Definition: assembly.h:52
libMesh::RBEIMAssembly::evaluate_basis_function
virtual void evaluate_basis_function(unsigned int var, const Elem &element, const std::vector< Point > &points, std::vector< Number > &values)
Evaluate variable var_number of this object's EIM basis function at the points points,...
Definition: rb_eim_assembly.C:65
EimTestRBAssemblyExpansion::A0_assembly
A0 A0_assembly
Definition: assembly.h:174
libMesh::FEMContext::get_element_fe
void get_element_fe(unsigned int var, FEGenericBase< OutputShape > *&fe) const
Accessor for interior finite element object for variable var for the largest dimension in the mesh.
Definition: fem_context.h:275
libMesh::ElemAssembly
ElemAssembly provides a per-element (interior and boundary) assembly functionality.
Definition: elem_assembly.h:38
ShiftedGaussian
Definition: assembly.h:39
EIM_IP_assembly
Definition: assembly.h:84
libMesh::DiffContext::get_elem_jacobian
const DenseMatrix< Number > & get_elem_jacobian() const
Const accessor for element Jacobian.
Definition: diff_context.h:283
libMesh::RBTheta
This class is part of the rbOOmit framework.
Definition: rb_theta.h:46
libMesh::Elem
This is the base class from which all geometric element types are derived.
Definition: elem.h:100
A0
Definition: assembly.h:39
ThetaA0
Definition: assembly.h:35
libMesh::RBThetaExpansion::attach_A_theta
virtual void attach_A_theta(RBTheta *theta_q_a)
Attach a pointer to a functor object that defines one of the theta_q_a terms.
Definition: rb_theta_expansion.C:62
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
EimTestRBAssemblyExpansion
Definition: assembly.h:163
libMesh::RBThetaExpansion
This class stores the set of RBTheta functor objects that define the "parameter-dependent expansion" ...
Definition: rb_theta_expansion.h:44
libMesh::RBEIMConstruction
This class is part of the rbOOmit framework.
Definition: rb_eim_construction.h:48
libMesh::RBParameters::get_value
Real get_value(const std::string &param_name) const
Get the value of the specific parameter.
Definition: rb_parameters.C:41
EIM_F::EIM_F
EIM_F(RBEIMConstruction &rb_eim_con_in, unsigned int basis_function_index_in)
Definition: assembly.h:111
EimTestRBThetaExpansion::theta_a_0
ThetaA0 theta_a_0
Definition: assembly.h:159
libMesh::FEMContext
This class provides all data required for a physics package (e.g.
Definition: fem_context.h:62