libMesh
L-qoi.C
Go to the documentation of this file.
1 #include "L-qoi.h"
2 
3 #include "libmesh/system.h"
4 
5 using namespace libMesh;
6 
8 {
9  // Only 1 qoi to worry about
10  sys.init_qois(1);
11 }
12 
14 {
15  FEMContext & c = cast_ref<FEMContext &>(context);
16 
17  // Now make sure we have requested all the data
18  // we need to build the linear system.
19  FEBase * elem_fe = nullptr;
20  c.get_element_fe(0, elem_fe);
21  elem_fe->get_JxW();
22  elem_fe->get_phi();
23  elem_fe->get_xyz();
24 }
25 
26 
27 // We only have one QoI, so we don't bother checking the qois argument
28 // to see if it was requested from us
30  const QoISet & /* qois */)
31 {
32  FEMContext & c = cast_ref<FEMContext &>(context);
33 
34  FEBase * elem_fe = nullptr;
35  c.get_element_fe(0, elem_fe);
36 
37  // Element Jacobian * quadrature weights for interior integration
38  const std::vector<Real> & JxW = elem_fe->get_JxW();
39 
40  const std::vector<Point> & xyz = elem_fe->get_xyz();
41 
42  unsigned int n_qpoints = c.get_element_qrule().n_points();
43 
44  Number dQoI_0 = 0.;
45 
46  // Loop over quadrature points
47  for (unsigned int qp = 0; qp != n_qpoints; qp++)
48  {
49  // Get co-ordinate locations of the current quadrature point
50  const Real xf = xyz[qp](0);
51  const Real yf = xyz[qp](1);
52 
53  // If in the sub-domain omega, add the contribution to the integral R
54  if (std::abs(xf - 0.875) <= 0.125 && std::abs(yf - 0.125) <= 0.125)
55  {
56  // Get the solution value at the quadrature point
57  Number T = c.interior_value(0, qp);
58 
59  // Update the elemental increment dR for each qp
60  dQoI_0 += JxW[qp] * T;
61  }
62  }
63 
64  // Update the computed value of the global functional R, by adding the contribution from this element
65  c.get_qois()[0] = c.get_qois()[0] + dQoI_0;
66 }
67 
68 // We only have one QoI, so we don't bother checking the qois argument
69 // to see if it was requested from us
71  const QoISet & /* qois */)
72 {
73  FEMContext & c = cast_ref<FEMContext &>(context);
74 
75  // First we get some references to cell-specific data that
76  // will be used to assemble the linear system.
77  FEBase * elem_fe = nullptr;
78  c.get_element_fe(0, elem_fe);
79 
80  // Element Jacobian * quadrature weights for interior integration
81  const std::vector<Real> & JxW = elem_fe->get_JxW();
82 
83  // The basis functions for the element
84  const std::vector<std::vector<Real>> & phi = elem_fe->get_phi();
85 
86  // The element quadrature points
87  const std::vector<Point > & q_point = elem_fe->get_xyz();
88 
89  // The number of local degrees of freedom in each variable
90  const unsigned int n_T_dofs = c.n_dof_indices(0);
91  unsigned int n_qpoints = c.get_element_qrule().n_points();
92 
93  // Fill the QoI RHS corresponding to this QoI. Since this is the 0th QoI
94  // we fill in the [0][i] subderivatives, i corresponding to the variable index.
95  // Our system has only one variable, so we only have to fill the [0][0] subderivative
97 
98  // Loop over the qps
99  for (unsigned int qp=0; qp != n_qpoints; qp++)
100  {
101  const Real x = q_point[qp](0);
102  const Real y = q_point[qp](1);
103 
104  // If in the sub-domain over which QoI 0 is supported, add contributions
105  // to the adjoint rhs
106  if (std::abs(x - 0.875) <= 0.125 && std::abs(y - 0.125) <= 0.125)
107  for (unsigned int i=0; i != n_T_dofs; i++)
108  Q(i) += JxW[qp]*phi[i][qp];
109  } // end of the quadrature point qp-loop
110 }
const std::vector< Number > & get_qois() const
Const accessor for QoI vector.
Definition: diff_context.h:317
Number interior_value(unsigned int var, unsigned int qp) const
Definition: fem_context.C:412
This class provides all data required for a physics package (e.g.
Definition: diff_context.h:55
Data structure for specifying which Quantities of Interest should be calculated in an adjoint or a pa...
Definition: qoi_set.h:45
unsigned int n_dof_indices() const
Total number of dof indices on the element.
Definition: diff_context.h:395
void init_qois(unsigned int n_qois)
Accessors for qoi and qoi_error_estimates vectors.
Definition: system.C:2371
The libMesh namespace provides an interface to certain functionality in the library.
Defines a dense subvector for use in finite element computations.
virtual void element_qoi(DiffContext &context, const QoISet &qois)
Does any work that needs to be done on elem in a quantity of interest assembly loop, outputting to elem_qoi.
Definition: L-qoi.C:29
virtual void init_context(DiffContext &context)
Prepares the result of a build_context() call for use.
Definition: L-qoi.C:13
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:96
This class provides all data required for a physics package (e.g.
Definition: fem_context.h:62
unsigned int n_points() const
Definition: quadrature.h:131
virtual void init_qoi_count(System &sys)
Initialize system qoi.
Definition: L-qoi.C:7
virtual void element_qoi_derivative(DiffContext &context, const QoISet &qois)
Does any work that needs to be done on elem in a quantity of interest derivative assembly loop...
Definition: L-qoi.C:70
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
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:277
const std::vector< DenseVector< Number > > & get_qoi_derivatives() const
Const accessor for QoI derivatives.
Definition: diff_context.h:329
This class forms the foundation from which generic finite elements may be derived.
const QBase & get_element_qrule() const
Accessor for element interior quadrature rule for the dimension of the current _elem.
Definition: fem_context.h:802