fem_context.h
Go to the documentation of this file.00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2012 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 00003 00004 // This library is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public 00006 // License as published by the Free Software Foundation; either 00007 // version 2.1 of the License, or (at your option) any later version. 00008 00009 // This library is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // Lesser General Public License for more details. 00013 00014 // You should have received a copy of the GNU Lesser General Public 00015 // License along with this library; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 00018 00019 00020 #ifndef LIBMESH_FEM_CONTEXT_H 00021 #define LIBMESH_FEM_CONTEXT_H 00022 00023 // Local Includes 00024 #include "libmesh/diff_context.h" 00025 #include "libmesh/id_types.h" 00026 #include "libmesh/fe_type.h" 00027 #include "libmesh/fe_base.h" 00028 #include "libmesh/vector_value.h" 00029 00030 #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES 00031 #include "libmesh/tensor_value.h" 00032 #endif 00033 00034 // C++ includes 00035 #include <map> 00036 00037 namespace libMesh 00038 { 00039 00040 // Forward Declarations 00041 class BoundaryInfo; 00042 class Elem; 00043 template <typename T> class FEGenericBase; 00044 typedef FEGenericBase<Real> FEBase; 00045 class QBase; 00046 class Point; 00047 template <typename T> class NumericVector; 00048 00061 // ------------------------------------------------------------ 00062 // FEMContext class definition 00063 00064 class FEMContext : public DiffContext 00065 { 00066 public: 00067 00071 explicit 00072 FEMContext (const System &sys); 00073 00077 virtual ~FEMContext (); 00078 00082 bool has_side_boundary_id(boundary_id_type id) const; 00083 00087 std::vector<boundary_id_type> side_boundary_ids() const; 00088 00094 Number interior_value(unsigned int var, unsigned int qp) const; 00095 00101 Number side_value(unsigned int var, unsigned int qp) const; 00102 00108 Number point_value(unsigned int var, const Point &p) const; 00109 00115 Gradient interior_gradient(unsigned int var, unsigned int qp) const; 00116 00122 Gradient side_gradient(unsigned int var, unsigned int qp) const; 00123 00129 Gradient point_gradient(unsigned int var, const Point &p) const; 00130 00131 #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES 00132 00137 Tensor interior_hessian(unsigned int var, unsigned int qp) const; 00138 00144 Tensor side_hessian(unsigned int var, unsigned int qp) const; 00145 00151 Tensor point_hessian(unsigned int var, const Point &p) const; 00152 00153 #endif // LIBMESH_ENABLE_SECOND_DERIVATIVES 00154 00160 Number fixed_interior_value(unsigned int var, unsigned int qp) const; 00161 00167 Number fixed_side_value(unsigned int var, unsigned int qp) const; 00168 00174 Number fixed_point_value(unsigned int var, const Point &p) const; 00175 00181 Gradient fixed_interior_gradient(unsigned int var, unsigned int qp) const; 00182 00188 Gradient fixed_side_gradient(unsigned int var, unsigned int qp) const; 00189 00195 Gradient fixed_point_gradient(unsigned int var, const Point &p) const; 00196 00197 #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES 00198 00203 Tensor fixed_interior_hessian(unsigned int var, unsigned int qp) const; 00204 00210 Tensor fixed_side_hessian(unsigned int var, unsigned int qp) const; 00211 00217 Tensor fixed_point_hessian (unsigned int var, const Point &p) const; 00218 00219 #endif // LIBMESH_ENABLE_SECOND_DERIVATIVES 00220 00224 template<typename OutputShape> 00225 void get_element_fe( unsigned int var, FEGenericBase<OutputShape> *& fe ) const; 00226 00230 template<typename OutputShape> 00231 void get_side_fe( unsigned int var, FEGenericBase<OutputShape> *& fe ) const; 00232 00236 template<typename OutputShape> 00237 void get_edge_fe( unsigned int var, FEGenericBase<OutputShape> *& fe ) const; 00238 00243 template<typename OutputType> 00244 void interior_value(unsigned int var, unsigned int qp, 00245 OutputType& u) const; 00246 00251 template<typename OutputType> 00252 void interior_values(unsigned int var, const NumericVector<Number> & _system_vector, 00253 std::vector<OutputType>& interior_values_vector) const; 00254 00259 template<typename OutputType> 00260 void side_value(unsigned int var, unsigned int qp, 00261 OutputType& u) const; 00262 00267 template<typename OutputType> 00268 void side_values(unsigned int var, const NumericVector<Number> & _system_vector, 00269 std::vector<OutputType>& side_values_vector) const; 00270 00275 template<typename OutputType> 00276 void point_value(unsigned int var, const Point &p, 00277 OutputType& u) const; 00278 00283 template<typename OutputType> 00284 void interior_gradient(unsigned int var, unsigned int qp, 00285 OutputType& du) const; 00286 00291 template<typename OutputType> 00292 void interior_gradients(unsigned int var, const NumericVector<Number> & _system_vector, 00293 std::vector<OutputType>& interior_gradients_vector) const; 00294 00299 template<typename OutputType> 00300 void side_gradient(unsigned int var, unsigned int qp, 00301 OutputType & du) const; 00302 00307 template<typename OutputType> 00308 void side_gradients(unsigned int var, const NumericVector<Number> & _system_vector, 00309 std::vector<OutputType>& side_gradients_vector) const; 00310 00315 template<typename OutputType> 00316 void point_gradient(unsigned int var, const Point &p, 00317 OutputType& grad_u) const; 00318 00319 #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES 00320 00324 template<typename OutputType> 00325 void interior_hessian(unsigned int var, unsigned int qp, 00326 OutputType& d2u) const; 00327 00333 template<typename OutputType> 00334 void interior_hessians(unsigned int var, const NumericVector<Number> & _system_vector, 00335 std::vector<OutputType>& d2u_vals) const; 00336 00341 template<typename OutputType> 00342 void side_hessian(unsigned int var, unsigned int qp, 00343 OutputType& d2u) const; 00344 00350 template<typename OutputType> 00351 void side_hessians(unsigned int var, const NumericVector<Number> & _system_vector, 00352 std::vector<OutputType>& d2u_vals) const; 00353 00358 template<typename OutputType> 00359 void point_hessian(unsigned int var, const Point &p, 00360 OutputType& hess_u) const; 00361 00362 #endif // LIBMESH_ENABLE_SECOND_DERIVATIVES 00363 00368 template<typename OutputType> 00369 void fixed_interior_value(unsigned int var, unsigned int qp, 00370 OutputType& u) const; 00371 00376 template<typename OutputType> 00377 void fixed_side_value(unsigned int var, unsigned int qp, 00378 OutputType& u) const; 00379 00384 template<typename OutputType> 00385 void fixed_point_value(unsigned int var, const Point &p, 00386 OutputType& u) const; 00387 00392 template<typename OutputType> 00393 void fixed_interior_gradient(unsigned int var, unsigned int qp, 00394 OutputType& grad_u) const; 00395 00400 template<typename OutputType> 00401 void fixed_side_gradient(unsigned int var, unsigned int qp, 00402 OutputType& grad_u) const; 00403 00408 template<typename OutputType> 00409 void fixed_point_gradient(unsigned int var, const Point &p, 00410 OutputType& grad_u) const; 00411 00412 #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES 00413 00417 template<typename OutputType> 00418 void fixed_interior_hessian(unsigned int var, unsigned int qp, 00419 OutputType& hess_u) const; 00420 00425 template<typename OutputType> 00426 void fixed_side_hessian(unsigned int var, unsigned int qp, 00427 OutputType& hess_u) const; 00428 00433 template<typename OutputType> 00434 void fixed_point_hessian(unsigned int var, const Point &p, 00435 OutputType& hess_u) const; 00436 00437 #endif // LIBMESH_ENABLE_SECOND_DERIVATIVES 00438 00443 template<typename OutputType> 00444 void interior_curl(unsigned int var, unsigned int qp, 00445 OutputType& curl_u) const; 00446 00451 template<typename OutputType> 00452 void interior_div(unsigned int var, unsigned int qp, 00453 OutputType& div_u) const; 00454 00459 // virtual void reinit(const FEMSystem&, Elem*); 00460 00461 // should be protected: 00467 virtual void elem_reinit(Real theta); 00468 00474 virtual void elem_side_reinit(Real theta); 00475 00481 virtual void elem_edge_reinit(Real theta); 00482 00486 virtual void pre_fe_reinit(const System&, const Elem *e); 00487 00491 void elem_fe_reinit(); 00492 00496 void side_fe_reinit(); 00497 00501 void edge_fe_reinit(); 00502 00506 const QBase* get_element_qrule() const 00507 { return this->element_qrule; } 00508 00512 const QBase* get_side_qrule() const 00513 { return this->side_qrule; } 00514 00518 const QBase* get_edge_qrule() const 00519 { return this->edge_qrule; } 00520 00529 virtual void set_mesh_system(System* sys) 00530 { this->_mesh_sys = sys; } 00531 00535 const System* get_mesh_system() const 00536 { return this->_mesh_sys; } 00537 00541 System* get_mesh_system() 00542 { return this->_mesh_sys; } 00543 00547 unsigned int get_mesh_x_var() const 00548 { return _mesh_x_var; } 00549 00555 void set_mesh_x_var(unsigned int x_var) 00556 { _mesh_x_var = x_var; } 00557 00561 unsigned int get_mesh_y_var() const 00562 { return _mesh_y_var; } 00563 00569 void set_mesh_y_var(unsigned int y_var) 00570 { _mesh_y_var = y_var; } 00571 00575 unsigned int get_mesh_z_var() const 00576 { return _mesh_z_var; } 00577 00583 void set_mesh_z_var(unsigned int z_var) 00584 { _mesh_z_var = z_var; } 00585 00589 const Elem& get_elem() const 00590 { return *elem; } 00591 00595 unsigned char get_side() const 00596 { return side; } 00597 00601 unsigned char get_edge() const 00602 { return edge; } 00603 00607 unsigned char get_dim() const 00608 { return dim; } 00609 00610 // should be protected?: 00614 std::map<FEType, FEBase *> element_fe; 00615 std::map<FEType, FEBase *> side_fe; 00616 std::map<FEType, FEBase *> edge_fe; 00617 00622 std::vector<FEBase *> element_fe_var; 00623 std::vector<FEBase *> side_fe_var; 00624 std::vector<FEBase *> edge_fe_var; 00625 00631 QBase *element_qrule; 00632 00638 QBase *side_qrule; 00639 00645 QBase *edge_qrule; 00646 00652 void elem_position_set(Real theta); 00653 00658 void elem_position_get(); 00659 00663 System *_mesh_sys; 00664 00668 unsigned int _mesh_x_var, _mesh_y_var, _mesh_z_var; 00669 00673 const Elem *elem; 00674 00678 unsigned char side; 00679 00683 unsigned char edge; 00684 00688 unsigned char dim; 00689 00690 protected: 00691 00695 template<typename OutputShape> 00696 AutoPtr<FEGenericBase<OutputShape> > build_new_fe( const FEGenericBase<OutputShape>* fe, const Point &p ) const; 00697 00701 std::map<FEType, FEAbstract*> _element_fe; 00702 std::map<FEType, FEAbstract*> _side_fe; 00703 std::map<FEType, FEAbstract*> _edge_fe; 00704 00705 00710 std::vector<FEAbstract*> _element_fe_var; 00711 std::vector<FEAbstract*> _side_fe_var; 00712 std::vector<FEAbstract*> _edge_fe_var; 00713 00718 BoundaryInfo* _boundary_info; 00719 00720 private: 00729 void _do_elem_position_set(Real theta); 00730 00736 void _update_time_from_system(Real theta); 00737 }; 00738 00739 00740 00741 // ------------------------------------------------------------ 00742 // FEMContext inline methods 00743 00744 inline 00745 void FEMContext::elem_position_set(Real theta) 00746 { 00747 if (_mesh_sys) 00748 this->_do_elem_position_set(theta); 00749 } 00750 00751 template<typename OutputShape> 00752 inline 00753 void FEMContext::get_element_fe( unsigned int var, FEGenericBase<OutputShape> *& fe ) const 00754 { 00755 libmesh_assert_less ( var, _element_fe_var.size() ); 00756 fe = libmesh_cast_ptr<FEGenericBase<OutputShape>*>( _element_fe_var[var] ); 00757 } 00758 00759 template<typename OutputShape> 00760 inline 00761 void FEMContext::get_side_fe( unsigned int var, FEGenericBase<OutputShape> *& fe ) const 00762 { 00763 libmesh_assert_less ( var, _side_fe_var.size() ); 00764 fe = libmesh_cast_ptr<FEGenericBase<OutputShape>*>( _side_fe_var[var] ); 00765 } 00766 00767 template<typename OutputShape> 00768 inline 00769 void FEMContext::get_edge_fe( unsigned int var, FEGenericBase<OutputShape> *& fe ) const 00770 { 00771 libmesh_assert_less ( var, _edge_fe_var.size() ); 00772 fe = libmesh_cast_ptr<FEGenericBase<OutputShape>*>( _edge_fe_var[var] ); 00773 } 00774 00775 00776 } // namespace libMesh 00777 00778 #endif // LIBMESH_FEM_CONTEXT_H
Site Created By: libMesh Developers
Last modified: February 05 2013 19:54:47 UTC
Hosted By: