Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include "SundanceRaviartThomas.hpp"
00043 #include "SundancePoint.hpp"
00044 #include "SundanceCellType.hpp"
00045 #include "SundanceSpatialDerivSpecifier.hpp"
00046 #include "PlayaExceptions.hpp"
00047 #include "SundanceTypeUtils.hpp"
00048 #include "SundanceObjectWithVerbosity.hpp"
00049 #include "SundanceOut.hpp"
00050 #include "SundanceADReal.hpp"
00051
00052 using namespace Sundance;
00053 using namespace Teuchos;
00054
00055
00056 RaviartThomas::RaviartThomas(int spatialDim)
00057 : HDivVectorBasis(spatialDim)
00058 {}
00059
00060 bool RaviartThomas::supportsCellTypePair(
00061 const CellType& maximalCellType,
00062 const CellType& cellType
00063 ) const
00064 {
00065 switch(maximalCellType)
00066 {
00067 case TriangleCell:
00068 switch(cellType)
00069 {
00070 case TriangleCell:
00071 case LineCell:
00072 case PointCell:
00073 return true;
00074 default:
00075 return false;
00076 }
00077 case TetCell:
00078 switch(cellType)
00079 {
00080 case TetCell:
00081 case TriangleCell:
00082 case LineCell:
00083 case PointCell:
00084 return true;
00085 default:
00086 return false;
00087 }
00088 default:
00089 return false;
00090 }
00091 }
00092
00093 std::string RaviartThomas::description() const
00094 {
00095 return "RaviartThomas()";
00096 }
00097
00098 int RaviartThomas::nReferenceDOFsWithoutFacets(
00099 const CellType& maximalCellType,
00100 const CellType& cellType
00101 ) const
00102 {
00103 if (dimension(cellType) == dimension(maximalCellType)-1)
00104 {
00105 return 1;
00106 }
00107 else
00108 {
00109 return 0;
00110 }
00111 }
00112
00113 void RaviartThomas::getReferenceDOFs(
00114 const CellType& maximalCellType,
00115 const CellType& cellType,
00116 Array<Array<Array<int> > >& dofs) const
00117 {
00118 switch(cellType)
00119 {
00120 case PointCell:
00121 dofs.resize(1);
00122 dofs[0] = tuple(Array<int>());
00123 return;
00124 case LineCell:
00125 dofs.resize(2);
00126 dofs[0] = tuple(Array<int>());
00127 dofs[1] = tuple<Array<int> >(tuple(0));
00128 return;
00129 case TriangleCell:
00130 dofs.resize(3);
00131 dofs[0] = tuple(Array<int>());
00132 dofs[1] = tuple<Array<int> >(tuple(0), tuple(1), tuple(2));
00133 dofs[2] = tuple(Array<int>());
00134 return;
00135 case TetCell:
00136 dofs.resize(4);
00137 dofs[0] = tuple(Array<int>());
00138 dofs[1] = tuple<Array<int> >(tuple(0), tuple(1), tuple(2), tuple(3));
00139 dofs[2] = tuple(Array<int>());
00140 dofs[3] = tuple(Array<int>());
00141 return;
00142 default:
00143 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "Cell type "
00144 << cellType << " not implemented in RaviartThomas basis");
00145 }
00146 }
00147
00148
00149
00150 bool RaviartThomas::lessThan(const BasisDOFTopologyBase* other) const
00151 {
00152 if (typeLessThan(this, other)) return true;
00153 if (typeLessThan(other, this)) return false;
00154
00155 return false;
00156 }
00157
00158
00159 void RaviartThomas::refEval(
00160 const CellType& cellType,
00161 const Array<Point>& pts,
00162 const SpatialDerivSpecifier& sds,
00163 Array<Array<Array<double> > >& result,
00164 int verbosity) const
00165 {
00166 const MultiIndex& deriv = sds.mi();
00167 switch(cellType) {
00168 case PointCell:
00169 {
00170 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "evaluation of RaviartThomas elements for PointCell not supported");
00171 }
00172 break;
00173 case LineCell:
00174 {
00175 result.resize(1);
00176 result[0].resize(pts.length());
00177 Array<ADReal> tmp;
00178 tmp.resize(2);
00179 for (int i=0;i<pts.length();i++) {
00180 ADReal x = ADReal( pts[i][0] , 0 , 1 );
00181 ADReal one(1.0,1);
00182 result[0][i].resize(2);
00183 tmp[0] = one - x;
00184 tmp[1] = x;
00185 if (deriv.order()==0) {
00186 for (int j=0;j<tmp.length();j++) {
00187 result[0][i][j] = tmp[j].value();
00188 }
00189 }
00190 else {
00191 for (int j=0;j<tmp.length();j++) {
00192 result[0][i][j] = tmp[j].gradient()[deriv.firstOrderDirection()];
00193 }
00194 }
00195 }
00196 }
00197 break;
00198 case TriangleCell:
00199 {
00200 result.resize(2);
00201 result[0].resize(pts.length());
00202 result[1].resize(pts.length());
00203 Array<ADReal> tmp0;
00204 Array<ADReal> tmp1;
00205 tmp0.resize(3);
00206 tmp1.resize(3);
00207 for (int i=0;i<pts.length();i++) {
00208 ADReal x = ADReal(pts[i][0],0,2);
00209 ADReal y = ADReal(pts[i][1],1,2);
00210 ADReal one(1.0,2);
00211 ADReal rt2(std::sqrt(2.0),2);
00212 result[0][i].resize(3);
00213 result[1][i].resize(3);
00214 tmp0[0] = x;
00215 tmp1[0] = y - one;
00216 tmp0[1] = rt2 * x;
00217 tmp1[1] = rt2 * y;
00218 tmp0[2] = x - one;
00219 tmp1[2] = y;
00220 if (deriv.order()==0) {
00221 for (int j=0;j<tmp0.length();j++) {
00222 result[0][i][j] = tmp0[j].value();
00223 result[1][i][j] = tmp1[j].value();
00224 }
00225 }
00226 else {
00227 for (int j=0;j<tmp0.length();j++) {
00228 result[0][i][j] = tmp0[j].gradient()[deriv.firstOrderDirection()];
00229 result[1][i][j] = tmp1[j].gradient()[deriv.firstOrderDirection()];
00230 }
00231 }
00232 }
00233 }
00234 break;
00235 case TetCell:
00236 {
00237 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "evaluation of RaviartThomas elements for TetCell not supported");
00238 }
00239 break;
00240 default:
00241 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "evaluation of RaviartThomas elements unknown cell type");
00242 break;
00243 }
00244
00245 return;
00246 }
00247
00248
00249 void RaviartThomas::print(std::ostream& os) const
00250 {
00251 os << "RaviartThomas(" << dim() << ")";
00252 }