$extrastylesheet
00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2014 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 // C++ includes 00020 00021 // Local includes 00022 #include "libmesh/elem.h" 00023 #include "libmesh/quadrature.h" 00024 00025 namespace libMesh 00026 { 00027 00028 void QBase::init(const ElemType t, 00029 unsigned int p) 00030 { 00031 // check to see if we have already 00032 // done the work for this quadrature rule 00033 if (t == _type && p == _p_level) 00034 return; 00035 else 00036 { 00037 _type = t; 00038 _p_level = p; 00039 } 00040 00041 00042 00043 switch(_dim) 00044 { 00045 case 0: 00046 this->init_0D(_type,_p_level); 00047 00048 return; 00049 00050 case 1: 00051 this->init_1D(_type,_p_level); 00052 00053 return; 00054 00055 case 2: 00056 this->init_2D(_type,_p_level); 00057 00058 return; 00059 00060 case 3: 00061 this->init_3D(_type,_p_level); 00062 00063 return; 00064 00065 default: 00066 libmesh_error_msg("Invalid dimension _dim = " << _dim); 00067 } 00068 } 00069 00070 00071 00072 void QBase::init (const Elem &elem, 00073 const std::vector<Real> & /* vertex_distance_func */, 00074 unsigned int p_level) 00075 { 00076 // dispatch generic implementation 00077 this->init(elem.type(), p_level); 00078 } 00079 00080 00081 00082 void QBase::init_0D(const ElemType, 00083 unsigned int) 00084 { 00085 _points.resize(1); 00086 _weights.resize(1); 00087 _points[0] = Point(0.); 00088 _weights[0] = 1.0; 00089 } 00090 00091 00092 00093 void QBase::scale(std::pair<Real, Real> old_range, 00094 std::pair<Real, Real> new_range) 00095 { 00096 // Make sure we are in 1D 00097 libmesh_assert_equal_to (_dim, 1); 00098 00099 Real 00100 h_new = new_range.second - new_range.first, 00101 h_old = old_range.second - old_range.first; 00102 00103 // Make sure that we have sane ranges 00104 libmesh_assert_greater (h_new, 0.); 00105 libmesh_assert_greater (h_old, 0.); 00106 00107 // Make sure there are some points 00108 libmesh_assert_greater (_points.size(), 0); 00109 00110 // Compute the scale factor 00111 Real scfact = h_new/h_old; 00112 00113 // We're mapping from old_range -> new_range 00114 for (unsigned int i=0; i<_points.size(); i++) 00115 { 00116 _points[i](0) = new_range.first + 00117 (_points[i](0) - old_range.first) * scfact; 00118 00119 // Scale the weights 00120 _weights[i] *= scfact; 00121 } 00122 } 00123 00124 00125 00126 00127 void QBase::tensor_product_quad(const QBase& q1D) 00128 { 00129 00130 const unsigned int np = q1D.n_points(); 00131 00132 _points.resize(np * np); 00133 00134 _weights.resize(np * np); 00135 00136 unsigned int q=0; 00137 00138 for (unsigned int j=0; j<np; j++) 00139 for (unsigned int i=0; i<np; i++) 00140 { 00141 _points[q](0) = q1D.qp(i)(0); 00142 _points[q](1) = q1D.qp(j)(0); 00143 00144 _weights[q] = q1D.w(i)*q1D.w(j); 00145 00146 q++; 00147 } 00148 } 00149 00150 00151 00152 00153 00154 void QBase::tensor_product_hex(const QBase& q1D) 00155 { 00156 const unsigned int np = q1D.n_points(); 00157 00158 _points.resize(np * np * np); 00159 00160 _weights.resize(np * np * np); 00161 00162 unsigned int q=0; 00163 00164 for (unsigned int k=0; k<np; k++) 00165 for (unsigned int j=0; j<np; j++) 00166 for (unsigned int i=0; i<np; i++) 00167 { 00168 _points[q](0) = q1D.qp(i)(0); 00169 _points[q](1) = q1D.qp(j)(0); 00170 _points[q](2) = q1D.qp(k)(0); 00171 00172 _weights[q] = q1D.w(i) * q1D.w(j) * q1D.w(k); 00173 00174 q++; 00175 } 00176 } 00177 00178 00179 00180 00181 void QBase::tensor_product_prism(const QBase& q1D, const QBase& q2D) 00182 { 00183 const unsigned int n_points1D = q1D.n_points(); 00184 const unsigned int n_points2D = q2D.n_points(); 00185 00186 _points.resize (n_points1D * n_points2D); 00187 _weights.resize (n_points1D * n_points2D); 00188 00189 unsigned int q=0; 00190 00191 for (unsigned int j=0; j<n_points1D; j++) 00192 for (unsigned int i=0; i<n_points2D; i++) 00193 { 00194 _points[q](0) = q2D.qp(i)(0); 00195 _points[q](1) = q2D.qp(i)(1); 00196 _points[q](2) = q1D.qp(j)(0); 00197 00198 _weights[q] = q2D.w(i) * q1D.w(j); 00199 00200 q++; 00201 } 00202 00203 } 00204 00205 00206 00207 00208 std::ostream& operator << (std::ostream& os, const QBase& q) 00209 { 00210 q.print_info(os); 00211 return os; 00212 } 00213 00214 } // namespace libMesh