void ParsedInteriorQoI::element_qoi_derivative( AssemblyContext& context, const unsigned int qoi_index ) { libMesh::FEBase* element_fe; context.get_element_fe<libMesh::Real>(0, element_fe); const std::vector<libMesh::Real> &JxW = element_fe->get_JxW(); const std::vector<libMesh::Point>& x_qp = element_fe->get_xyz(); // Local DOF count and quadrature point count const unsigned int n_u_dofs = context.get_dof_indices().size(); unsigned int n_qpoints = context.get_element_qrule().n_points(); // Local solution vector - non-const version for finite // differenting purposes libMesh::DenseVector<libMesh::Number>& elem_solution = const_cast<libMesh::DenseVector<libMesh::Number>&> (context.get_elem_solution()); /*! \todo Need to generalize this to the multiple QoI case */ libMesh::DenseVector<libMesh::Number> &Qu = context.get_qoi_derivatives()[qoi_index]; for( unsigned int qp = 0; qp != n_qpoints; qp++ ) { // Central finite differencing to approximate derivatives. // FIXME - we should hook the FParserAD stuff into // ParsedFEMFunction for( unsigned int i = 0; i != n_u_dofs; ++i ) { libMesh::Number ¤t_solution = elem_solution(i); const libMesh::Number original_solution = current_solution; current_solution = original_solution + libMesh::TOLERANCE; const libMesh::Number plus_val = (*qoi_functional)(context, x_qp[qp], context.get_time()); current_solution = original_solution - libMesh::TOLERANCE; const libMesh::Number minus_val = (*qoi_functional)(context, x_qp[qp], context.get_time()); Qu(i) += (plus_val - minus_val) * (0.5 / libMesh::TOLERANCE) * JxW[qp]; // Don't forget to restore the correct solution... current_solution = original_solution; } } }
void Vorticity::element_qoi_derivative( libMesh::DiffContext &context, const libMesh::QoISet & ) { libMesh::FEMContext &c = libmesh_cast_ref<libMesh::FEMContext&>(context); if( _subdomain_ids.find( (c.elem)->subdomain_id() ) != _subdomain_ids.end() ) { // Element libMesh::FEBase* element_fe; c.get_element_fe<libMesh::Real>(this->_u_var, element_fe); // Jacobian times integration weights const std::vector<libMesh::Real> &JxW = element_fe->get_JxW(); // Grad of basis functions const std::vector<std::vector<libMesh::RealGradient> >& du_phi = c.element_fe_var[_u_var]->get_dphi(); const std::vector<std::vector<libMesh::RealGradient> >& dv_phi = c.element_fe_var[_v_var]->get_dphi(); // Local DOF count and quadrature point count const unsigned int n_T_dofs = c.dof_indices_var[0].size(); unsigned int n_qpoints = (c.get_element_qrule())->n_points(); // Warning: we assume here that vorticity is the only QoI! // This should be consistent with the assertion in grins_mesh_adaptive_solver.C /*! \todo Need to generalize this to the multiple QoI case */ libMesh::DenseSubVector<Number> &Qu = *c.elem_qoi_subderivatives[0][0]; libMesh::DenseSubVector<Number> &Qv = *c.elem_qoi_subderivatives[0][1]; // Integration loop for( unsigned int qp = 0; qp != n_qpoints; qp++ ) { for( unsigned int i = 0; i != n_T_dofs; i++ ) { Qu(i) += - dv_phi[i][qp](1) * JxW[qp]; Qv(i) += du_phi[i][qp](0) * JxW[qp]; } } } return; }