libMesh
Public Member Functions | Public Attributes | List of all members
CoupledSystemQoI Class Reference

#include <H-qoi.h>

Inheritance diagram for CoupledSystemQoI:
[legend]

Public Member Functions

 CoupledSystemQoI ()
 
virtual ~CoupledSystemQoI ()
 
virtual void init_qoi (std::vector< Number > &sys_qoi)
 
virtual void postprocess ()
 
virtual void side_qoi_derivative (DiffContext &context, const QoISet &qois)
 Does any work that needs to be done on side of elem in a quantity of interest derivative assembly loop, outputting to elem_qoi_derivative. More...
 
virtual void side_qoi (DiffContext &context, const QoISet &qois)
 Does any work that needs to be done on side of elem in a quantity of interest assembly loop, outputting to elem_qoi. More...
 
virtual UniquePtr< DifferentiableQoIclone ()
 Copy of this object. More...
 
virtual void init_qoi (std::vector< Number > &)
 Initialize system qoi. More...
 
virtual void clear_qoi ()
 Clear all the data structures associated with the QoI. More...
 
virtual void element_qoi (DiffContext &, const QoISet &)
 Does any work that needs to be done on elem in a quantity of interest assembly loop, outputting to elem_qoi. More...
 
virtual void element_qoi_derivative (DiffContext &, const QoISet &)
 Does any work that needs to be done on elem in a quantity of interest derivative assembly loop, outputting to elem_qoi_derivative. More...
 
virtual void init_context (DiffContext &)
 Prepares the result of a build_context() call for use. More...
 
virtual void thread_join (std::vector< Number > &qoi, const std::vector< Number > &other_qoi, const QoISet &qoi_indices)
 Method to combine thread-local qois. More...
 
virtual void parallel_op (const Parallel::Communicator &communicator, std::vector< Number > &sys_qoi, std::vector< Number > &local_qoi, const QoISet &qoi_indices)
 Method to populate system qoi data structure with process-local qoi. More...
 
virtual void finalize_derivative (NumericVector< Number > &derivatives, std::size_t qoi_index)
 Method to finalize qoi derivatives which require more than just a simple sum of element contributions. More...
 

Public Attributes

bool assemble_qoi_sides
 If assemble_qoi_sides is true (it is false by default), the assembly loop for a quantity of interest or its derivatives will loop over domain boundary sides. More...
 
bool assemble_qoi_internal_sides
 If assemble_qoi_internal_sides is true (it is false by default), the assembly loop for a quantity of interest or its derivatives will loop over element sides which do not fall on domain boundaries. More...
 
bool assemble_qoi_elements
 If assemble_qoi_elements is false (it is true by default), the assembly loop for a quantity of interest or its derivatives will skip computing on mesh elements, and will only compute on mesh sides. More...
 

Detailed Description

Definition at line 15 of file H-qoi.h.

Constructor & Destructor Documentation

CoupledSystemQoI::CoupledSystemQoI ( )

Definition at line 18 of file H-qoi.h.

18 {}
virtual CoupledSystemQoI::~CoupledSystemQoI ( )
virtual

Definition at line 19 of file H-qoi.h.

19 {}

Member Function Documentation

virtual void libMesh::DifferentiableQoI::clear_qoi ( )
virtualinherited

Clear all the data structures associated with the QoI.

Definition at line 74 of file diff_qoi.h.

Referenced by libMesh::DifferentiableSystem::clear().

74 {}
virtual UniquePtr<DifferentiableQoI> CoupledSystemQoI::clone ( )
virtual

Copy of this object.

User should override to copy any needed state.

Implements libMesh::DifferentiableQoI.

Definition at line 30 of file H-qoi.h.

31  {
32  DifferentiableQoI * my_clone = new CoupledSystemQoI;
33  *my_clone = *this;
34  return UniquePtr<DifferentiableQoI>(my_clone);
35  }
CoupledSystemQoI()
Definition: H-qoi.h:18
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
This class provides a specific system class.
Definition: diff_qoi.h:49
virtual void libMesh::DifferentiableQoI::element_qoi ( DiffContext ,
const QoISet  
)
virtualinherited

Does any work that needs to be done on elem in a quantity of interest assembly loop, outputting to elem_qoi.

Only qois included in the supplied QoISet need to be assembled.

Reimplemented in LaplaceQoI.

Definition at line 107 of file diff_qoi.h.

109  {}
virtual void libMesh::DifferentiableQoI::element_qoi_derivative ( DiffContext ,
const QoISet  
)
virtualinherited

Does any work that needs to be done on elem in a quantity of interest derivative assembly loop, outputting to elem_qoi_derivative.

Only qois included in the supplied QoISet need their derivatives assembled.

Reimplemented in HeatSystem, LaplaceSystem, LaplaceSystem, and LaplaceQoI.

Definition at line 119 of file diff_qoi.h.

121  {}
void libMesh::DifferentiableQoI::finalize_derivative ( NumericVector< Number > &  derivatives,
std::size_t  qoi_index 
)
virtualinherited

Method to finalize qoi derivatives which require more than just a simple sum of element contributions.

Definition at line 51 of file diff_qoi.C.

Referenced by libMesh::FEMSystem::assemble_qoi_derivative(), and libMesh::DifferentiableQoI::init_context().

52 {
53  // by default, do nothing
54 }
virtual void libMesh::DifferentiableQoI::init_context ( DiffContext )
virtualinherited

Prepares the result of a build_context() call for use.

Most FEMSystem-based problems will need to reimplement this in order to call FE::get_*() as their particular QoI requires.

Reimplemented in libMesh::FEMSystem, HeatSystem, CoupledSystem, ElasticitySystem, LaplaceSystem, CurlCurlSystem, LaplaceSystem, PoissonSystem, LaplaceSystem, LaplaceSystem, CurlCurlSystem, L2System, SolidSystem, NavierSystem, HeatSystem, and LaplaceQoI.

Definition at line 152 of file diff_qoi.h.

References libMesh::DifferentiableQoI::clone(), libMesh::DifferentiableQoI::finalize_derivative(), libMesh::DifferentiableQoI::parallel_op(), and libMesh::DifferentiableQoI::thread_join().

152 {}
void CoupledSystemQoI::init_qoi ( std::vector< Number > &  sys_qoi)
virtual

Definition at line 8 of file H-qoi.C.

9 {
10  //Only 1 qoi to worry about
11  sys_qoi.resize(1);
12 }
virtual void libMesh::DifferentiableQoI::init_qoi ( std::vector< Number > &  )
virtualinherited

Initialize system qoi.

By default, does nothing in order to maintain backward compatibility for FEMSystem applications that control qoi.

Definition at line 68 of file diff_qoi.h.

Referenced by libMesh::DifferentiableSystem::attach_qoi().

68 {}
void libMesh::DifferentiableQoI::parallel_op ( const Parallel::Communicator communicator,
std::vector< Number > &  sys_qoi,
std::vector< Number > &  local_qoi,
const QoISet qoi_indices 
)
virtualinherited

Method to populate system qoi data structure with process-local qoi.

By default, simply sums process qois into system qoi.

Definition at line 39 of file diff_qoi.C.

References libMesh::Parallel::Communicator::sum().

Referenced by libMesh::FEMSystem::assemble_qoi(), and libMesh::DifferentiableQoI::init_context().

43 {
44  // Sum everything into local_qoi
45  communicator.sum(local_qoi);
46 
47  // Now put into system qoi
48  sys_qoi = local_qoi;
49 }
MPI_Comm communicator
Communicator object for talking with subsets of processors.
Definition: parallel.h:181
virtual void CoupledSystemQoI::postprocess ( void  )
virtual

Definition at line 22 of file H-qoi.h.

22 {}
void CoupledSystemQoI::side_qoi ( DiffContext ,
const QoISet  
)
virtual

Does any work that needs to be done on side of elem in a quantity of interest assembly loop, outputting to elem_qoi.

Only qois included in the supplied QoISet need to be assembled.

Reimplemented from libMesh::DifferentiableQoI.

Definition at line 78 of file H-qoi.C.

References libMesh::DiffContext::get_qois(), libMesh::FEMContext::get_side_fe(), libMesh::FEMContext::get_side_qrule(), libMesh::FEMContext::has_side_boundary_id(), libmesh_nullptr, libMesh::QBase::n_points(), libMesh::Real, libMesh::FEMContext::side_value(), and libMesh::x.

80 {
81 
82  FEMContext & c = cast_ref<FEMContext &>(context);
83 
84  // First we get some references to cell-specific data that
85  // will be used to assemble the linear system.
86  FEBase * side_fe = libmesh_nullptr;
87  c.get_side_fe(0, side_fe);
88 
89  // Element Jacobian * quadrature weights for interior integration
90  const std::vector<Real> & JxW = side_fe->get_JxW();
91  const std::vector<Point> & q_point = side_fe->get_xyz();
92 
93  // Loop over qp's, compute the function at each qp and add
94  // to get the QoI
95  unsigned int n_qpoints = c.get_side_qrule().n_points();
96 
97  Number dQoI_0 = 0.;
98  Number u = 0.;
99  Number C = 0.;
100 
101  // If side is on the left outlet
102  if (c.has_side_boundary_id(2))
103  {
104  //Loop over all the qps on this side
105  for (unsigned int qp=0; qp != n_qpoints; qp++)
106  {
107  Real x = q_point[qp](0);
108 
109  if (x < 0.)
110  {
111  // Get u and C at the qp
112  u = c.side_value(0, qp);
113  C = c.side_value(3, qp);
114 
115  dQoI_0 += JxW[qp] * -u * C;
116  } // end if
117  } // end quadrature loop
118  } // end if on bdry
119 
120  c.get_qois()[0] += dQoI_0;
121 }
const QBase & get_side_qrule() const
Accessor for element side quadrature rule for the dimension of the current _elem. ...
Definition: fem_context.h:772
const class libmesh_nullptr_t libmesh_nullptr
PetscErrorCode Vec x
const std::vector< Number > & get_qois() const
Const accessor for QoI vector.
Definition: diff_context.h:318
This class provides all data required for a physics package (e.g.
Definition: fem_context.h:61
bool has_side_boundary_id(boundary_id_type id) const
Reports if the boundary id is found on the current side.
Definition: fem_context.C:209
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Number side_value(unsigned int var, unsigned int qp) const
Definition: fem_context.C:575
void get_side_fe(unsigned int var, FEGenericBase< OutputShape > *&fe) const
Accessor for edge/face (2D/3D) finite element object for variable var for the largest dimension in th...
Definition: fem_context.h:299
unsigned int n_points() const
Definition: quadrature.h:113
This class forms the foundation from which generic finite elements may be derived.
void CoupledSystemQoI::side_qoi_derivative ( DiffContext ,
const QoISet  
)
virtual

Does any work that needs to be done on side of elem in a quantity of interest derivative assembly loop, outputting to elem_qoi_derivative.

Only qois included in the supplied QoISet need their derivatives assembled.

Reimplemented from libMesh::DifferentiableQoI.

Definition at line 17 of file H-qoi.C.

References libMesh::DiffContext::get_dof_indices(), libMesh::DiffContext::get_qoi_derivatives(), libMesh::FEMContext::get_side_fe(), libMesh::FEMContext::get_side_qrule(), libMesh::FEMContext::has_side_boundary_id(), libmesh_nullptr, libMesh::QBase::n_points(), libMesh::Real, libMesh::FEMContext::side_value(), and libMesh::x.

19 {
20  FEMContext & c = cast_ref<FEMContext &>(context);
21 
22  FEBase * side_fe = libmesh_nullptr;
23  c.get_side_fe(0, side_fe);
24 
25  // Element Jacobian * quadrature weights for interior integration
26  const std::vector<Real> & JxW = side_fe->get_JxW();
27 
28  // Side basis functions
29  const std::vector<std::vector<Real>> & phi = side_fe->get_phi();
30  const std::vector<Point > & q_point = side_fe->get_xyz();
31 
32  // The number of local degrees of freedom in each variable
33  const unsigned int n_u_dofs = c.get_dof_indices(1).size();
34 
37 
38  // Now we will build the element Jacobian and residual.
39  // Constructing the residual requires the solution and its
40  // gradient from the previous timestep. This must be
41  // calculated at each quadrature point by summing the
42  // solution degree-of-freedom values by the appropriate
43  // weight functions.
44  unsigned int n_qpoints = c.get_side_qrule().n_points();
45 
46  Number u = 0.;
47  Number C = 0.;
48 
49  // // If side is on outlet
50  if (c.has_side_boundary_id(2))
51  {
52  // Loop over all the qps on this side
53  for (unsigned int qp=0; qp != n_qpoints; qp++)
54  {
55  Real x = q_point[qp](0);
56 
57  // If side is on left outlet
58  if (x < 0.)
59  {
60  // Get u at the qp
61  u = c.side_value(0, qp);
62  C = c.side_value(3, qp);
63 
64  // Add the contribution from each basis function
65  for (unsigned int i=0; i != n_u_dofs; i++)
66  {
67  Qu(i) += JxW[qp] * -phi[i][qp] * C;
68  QC(i) += JxW[qp] * phi[i][qp] * -u;
69  }
70  } // end if
71 
72  } // end quadrature loop
73 
74  } // end if on outlet
75 }
const QBase & get_side_qrule() const
Accessor for element side quadrature rule for the dimension of the current _elem. ...
Definition: fem_context.h:772
const std::vector< dof_id_type > & get_dof_indices() const
Accessor for element dof indices.
Definition: diff_context.h:366
const class libmesh_nullptr_t libmesh_nullptr
Defines a dense subvector for use in finite element computations.
PetscErrorCode Vec x
const std::vector< DenseVector< Number > > & get_qoi_derivatives() const
Const accessor for QoI derivatives.
Definition: diff_context.h:330
This class provides all data required for a physics package (e.g.
Definition: fem_context.h:61
bool has_side_boundary_id(boundary_id_type id) const
Reports if the boundary id is found on the current side.
Definition: fem_context.C:209
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Number side_value(unsigned int var, unsigned int qp) const
Definition: fem_context.C:575
void get_side_fe(unsigned int var, FEGenericBase< OutputShape > *&fe) const
Accessor for edge/face (2D/3D) finite element object for variable var for the largest dimension in th...
Definition: fem_context.h:299
unsigned int n_points() const
Definition: quadrature.h:113
This class forms the foundation from which generic finite elements may be derived.
void libMesh::DifferentiableQoI::thread_join ( std::vector< Number > &  qoi,
const std::vector< Number > &  other_qoi,
const QoISet qoi_indices 
)
virtualinherited

Method to combine thread-local qois.

By default, simply sums thread qois.

Definition at line 31 of file diff_qoi.C.

Referenced by libMesh::DifferentiableQoI::init_context().

34 {
35  for (std::size_t i=0; i != qoi.size(); ++i)
36  qoi[i] += other_qoi[i];
37 }

Member Data Documentation

bool libMesh::DifferentiableQoI::assemble_qoi_elements
inherited

If assemble_qoi_elements is false (it is true by default), the assembly loop for a quantity of interest or its derivatives will skip computing on mesh elements, and will only compute on mesh sides.

Definition at line 98 of file diff_qoi.h.

bool libMesh::DifferentiableQoI::assemble_qoi_internal_sides
inherited

If assemble_qoi_internal_sides is true (it is false by default), the assembly loop for a quantity of interest or its derivatives will loop over element sides which do not fall on domain boundaries.

Definition at line 90 of file diff_qoi.h.

bool libMesh::DifferentiableQoI::assemble_qoi_sides
inherited

If assemble_qoi_sides is true (it is false by default), the assembly loop for a quantity of interest or its derivatives will loop over domain boundary sides.

To add domain interior sides, also set assemble_qoi_internal_sides to true.

Definition at line 82 of file diff_qoi.h.

Referenced by main().


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