libMesh
element_postprocess.C
Go to the documentation of this file.
1 // General libMesh includes
2 #include "libmesh/libmesh_common.h"
3 #include "libmesh/elem.h"
4 #include "libmesh/fe_base.h"
5 #include "libmesh/fem_context.h"
6 #include "libmesh/point.h"
7 #include "libmesh/quadrature.h"
8 #include "libmesh/threads.h"
9 
10 // Local includes
11 #include "L-shaped.h"
12 
13 // Bring in everything from the libMesh namespace
14 using namespace libMesh;
15 
16 // Define the postprocess function to compute QoI 0, the integral of the the solution
17 // over a subdomain
19 {
20  FEMContext & c = cast_ref<FEMContext &>(context);
21 
22  FEBase * elem_fe = nullptr;
23  c.get_element_fe(0, elem_fe);
24 
25  // Element Jacobian * quadrature weights for interior integration
26  const std::vector<Real> & JxW = elem_fe->get_JxW();
27 
28  const std::vector<Point> & xyz = elem_fe->get_xyz();
29 
30  // The number of local degrees of freedom in each variable
31  unsigned int n_qpoints = c.get_element_qrule().n_points();
32 
33  // The function R = int_{omega} T dR
34  // omega is a subset of Omega (the whole domain), omega = [0.75, 1.0] x [0.0, 0.25]
35  Number dQoI_0 = 0.;
36 
37  // Loop over quadrature points
38  for (unsigned int qp = 0; qp != n_qpoints; qp++)
39  {
40  // Get co-ordinate locations of the current quadrature point
41  const Real x = xyz[qp](0);
42  const Real y = xyz[qp](1);
43 
44  // If in the sub-domain omega, add the contribution to the integral R
45  if (std::abs(x - 0.875) <= 0.125 && std::abs(y - 0.125) <= 0.125)
46  {
47  // Get the solution value at the quadrature point
48  Number T = c.interior_value(0, qp);
49 
50  // Update the elemental increment dR for each qp
51  dQoI_0 += JxW[qp] * T;
52  }
53  }
54 
55  static Threads::spin_mutex local_mtx;
56  Threads::spin_mutex::scoped_lock lock(local_mtx);
57  // Update the computed value of the global functional R, by adding the contribution from this element
58  computed_QoI[0] = computed_QoI[0] + dQoI_0;
59 }
Number interior_value(unsigned int var, unsigned int qp) const
Definition: fem_context.C:404
This class provides all data required for a physics package (e.g.
Definition: diff_context.h:55
The libMesh namespace provides an interface to certain functionality in the library.
ADRealEigenVector< T, D, asd > abs(const ADRealEigenVector< T, D, asd > &)
Definition: type_vector.h:57
virtual void element_postprocess(DiffContext &context)
Does any work that needs to be done on elem in a postprocessing loop.
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:123
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
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