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 = libmesh_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 = libmesh_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 = libmesh_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  // Now we will build the affine operator
136  unsigned int n_qpoints = c.get_element_qrule().n_points();
137 
138  std::vector<Number> eim_values;
139  evaluate_basis_function(eim_var,
140  c.get_elem(),
141  c.get_element_qrule(),
142  eim_values);
143 
144  for (unsigned int qp=0; qp != n_qpoints; qp++)
145  for (unsigned int i=0; i != n_u_dofs; i++)
146  c.get_elem_residual()(i) += JxW[qp] * (eim_values[qp]*phi[i][qp]);
147  }
148 };
149 
150 // Define an RBThetaExpansion class for this PDE
152 {
157  {
158  attach_A_theta(&theta_a_0);
159  }
160 
161  // The RBTheta member variables
163 };
164 
165 // Define an RBAssemblyExpansion class for this PDE
167 {
172  {
173  attach_A_assembly(&A0_assembly);
174  }
175 
176  // A0 assembly object
178 };
179 
180 #endif
RealVectorValue RealGradient
A simple functor class that provides a RBParameter-dependent function.
Real get_value(const std::string &param_name) const
Get the value of the specific parameter.
Definition: rb_parameters.C:45
This class is part of the rbOOmit framework.
const std::vector< dof_id_type > & get_dof_indices() const
Accessor for element dof indices.
Definition: diff_context.h:366
This is the base class from which all geometric element types are derived.
Definition: elem.h:89
const class libmesh_nullptr_t libmesh_nullptr
EimTestRBAssemblyExpansion()
Constructor.
Definition: assembly.h:171
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:262
const DenseVector< Number > & get_elem_residual() const
Const accessor for element residual.
Definition: diff_context.h:248
const Elem & get_elem() const
Accessor for current Elem object.
Definition: fem_context.h:871
This class stores the set of RBTheta functor objects that define the "parameter-dependent expansion" ...
EimTestRBThetaExpansion()
Constructor.
Definition: assembly.h:156
This class provides functionality required to define an assembly object that arises from an "Empirica...
virtual void interior_assembly(FEMContext &c)
Perform the element interior assembly.
Definition: assembly.h:87
const DenseMatrix< Number > & get_elem_jacobian() const
Const accessor for element Jacobian.
Definition: diff_context.h:282
EIM_F(RBEIMConstruction &rb_eim_con_in, unsigned int basis_function_index_in)
Definition: assembly.h:111
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
This class provides all data required for a physics package (e.g.
Definition: fem_context.h:61
This class is part of the rbOOmit framework.
Definition: rb_parameters.h:42
FEGenericBase< Real > FEBase
double pow(double a, int b)
Definition: assembly.h:39
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
This class stores the set of ElemAssembly functor objects that define the "parameter-independent expa...
ElemAssembly provides a per-element (interior and boundary) assembly functionality.
Definition: elem_assembly.h:38
const QBase & get_element_qrule() const
Accessor for element interior quadrature rule for the dimension of the current _elem.
Definition: fem_context.h:765
virtual void interior_assembly(FEMContext &c)
Perform the element interior assembly.
Definition: assembly.h:57
This class is part of the rbOOmit framework.
Definition: rb_theta.h:46
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
unsigned int n_points() const
Definition: quadrature.h:113
virtual Number evaluate(const RBParameters &)
Evaluate the functor object for the given parameter.
Definition: assembly.h:52
virtual void interior_assembly(FEMContext &c)
Perform the element interior assembly.
Definition: assembly.h:117