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 "SundanceMeshBase.hpp"
00043 #include "SundanceMesh.hpp"
00044 #include "PlayaExceptions.hpp"
00045 #include "Teuchos_Time.hpp"
00046 #include "Teuchos_TimeMonitor.hpp"
00047 #include "PlayaTabs.hpp"
00048
00049 using namespace Sundance;
00050 using namespace Sundance;
00051 using namespace Teuchos;
00052 using namespace Sundance;
00053
00054
00055
00056 MeshBase::MeshBase(int dim, const MPIComm& comm,
00057 const MeshEntityOrder& order)
00058 : dim_(dim),
00059 comm_(comm),
00060 order_(order),
00061 reorderer_(Mesh::defaultReorderer().createInstance(this)),
00062 validWeights_(true),
00063 specialWeights_(),
00064 curvePoints_Are_Valid_(true),
00065 nrCurvesForIntegral_(0),
00066 curvePoints_() ,
00067 curveDerivative_(),
00068 curveNormal_(),
00069 curveID_to_ArrayIndex_()
00070 { specialWeights_.resize(dim_);
00071 curvePoints_.resize(0);
00072 curveDerivative_.resize(0);
00073 curveNormal_.resize(0);
00074 }
00075
00076 const int* MeshBase::elemZeroFacetView(int maxCellLID) const
00077 {
00078 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error,
00079 "MeshBase::elemZeroFacetView() is deprecated");
00080 return (const int*) 0;
00081 }
00082
00083
00084 Point MeshBase::centroid(int cellDim, int cellLID) const
00085 {
00086 if (cellDim==0) return nodePosition(cellLID);
00087 int dummy;
00088 Point x = nodePosition(facetLID(cellDim, cellLID, 0, 0, dummy));
00089 int nf = numFacets(cellDim, cellLID, 0);
00090 for (int f=1; f<nf; f++)
00091 x += nodePosition(facetLID(cellDim, cellLID, 0, f, dummy));
00092 return x / ((double) nf);
00093 }
00094
00095 void MeshBase::outwardNormals(
00096 const Array<int>& cellLIDs,
00097 Array<Point>& outwardNormals
00098 ) const
00099 {
00100 int D = spatialDim();
00101 outwardNormals.resize(cellLIDs.size());
00102 for (int c=0; c<cellLIDs.size(); c++)
00103 {
00104 int f=-1;
00105 TEUCHOS_TEST_FOR_EXCEPTION(numMaxCofacets(D-1, cellLIDs[c]) > 1,
00106 std::runtime_error,
00107 "cell #" << cellLIDs[c] << " is not a boundary cell");
00108 int maxLID = maxCofacetLID(D-1, cellLIDs[c], 0, f);
00109 Point cInterior = centroid(D, maxLID);
00110 Point cBdry = centroid(D-1, cellLIDs[c]);
00111 Point q = cBdry - cInterior;
00112 Point s;
00113 if (D==1)
00114 {
00115 s = Point(1.0);
00116 }
00117 else if (D==2)
00118 {
00119 Point A = nodePosition(facetLID(D-1, cellLIDs[c], 0, 0, f));
00120 Point B = nodePosition(facetLID(D-1, cellLIDs[c], 0, 1, f));
00121 Point t = B - A;
00122 s = Point(-t[1], t[0]);
00123 }
00124 else
00125 {
00126 Point A = nodePosition(facetLID(D-1, cellLIDs[c], 0, 0, f));
00127 Point B = nodePosition(facetLID(D-1, cellLIDs[c], 0, 1, f));
00128 Point C = nodePosition(facetLID(D-1, cellLIDs[c], 0, 2, f));
00129 s = cross(B-A, C-A);
00130 }
00131 if (q * s > 0.0)
00132 {
00133 outwardNormals[c] = s/::sqrt(s*s);
00134 }
00135 else
00136 {
00137 outwardNormals[c] = -s/::sqrt(s*s);
00138 }
00139 }
00140 }
00141
00142
00143 void MeshBase::tangentsToEdges(
00144 const Array<int>& cellLIDs,
00145 Array<Point>& tangentVectors
00146 ) const
00147 {
00148 TEUCHOS_TEST_FOR_EXCEPT(spatialDim() <= 1);
00149
00150 tangentVectors.resize(cellLIDs.size());
00151
00152 for (int c=0; c<cellLIDs.size(); c++)
00153 {
00154 int fOrient=1;
00155 Point A = nodePosition(facetLID(1, cellLIDs[c], 0, 0, fOrient));
00156 Point B = nodePosition(facetLID(1, cellLIDs[c], 0, 1, fOrient));
00157 Point t = B - A;
00158 tangentVectors[c] = t/(sqrt(t*t));
00159 }
00160 }
00161
00162
00163
00164
00165 void MeshBase::getFacetArray(int cellDim, int cellLID, int facetDim,
00166 Array<int>& facetLIDs,
00167 Array<int>& facetOrientations) const
00168 {
00169 int nf = numFacets(cellDim, cellLID, facetDim);
00170 facetLIDs.resize(nf);
00171 facetOrientations.resize(nf);
00172 for (int f=0; f<nf; f++)
00173 {
00174 facetLIDs[f] = facetLID(cellDim, cellLID, facetDim, f,
00175 facetOrientations[f]);
00176 }
00177 }
00178
00179
00180 void MeshBase::getLabels(int cellDim, const Array<int>& cellLID,
00181 Array<int>& labels) const
00182 {
00183 labels.resize(cellLID.size());
00184 for (int i=0; i<cellLID.size(); i++) labels[i] = label(cellDim, cellLID[i]);
00185 }
00186
00187
00188 void MeshBase::getMaxCofacetLIDs(
00189 const Array<int>& cellLIDs,
00190 MaximalCofacetBatch& cofacets) const
00191 {
00192 TEUCHOS_TEST_FOR_EXCEPT(cellLIDs.size()==0);
00193 int d = spatialDim() - 1;
00194 int nc = numMaxCofacets(d, cellLIDs[0]);
00195
00196 cofacets.reset(cellLIDs.size(), nc);
00197
00198 for (int i=0; i<cellLIDs.size(); i++)
00199 {
00200 int f1;
00201 int cofacet1 = maxCofacetLID(d, cellLIDs[i], 0, f1);
00202 if (nc==1) cofacets.addSingleCofacet(i, cofacet1, f1);
00203 else
00204 {
00205 int f2;
00206 int cofacet2 = maxCofacetLID(d, cellLIDs[i], 1, f2);
00207 cofacets.addTwoCofacets(i, cofacet1, f1, cofacet2, f2);
00208 }
00209 }
00210 }
00211
00212 void MeshBase::getLIDsForLabel(int cellDim, int labelToCheck,
00213 Array<int>& cellLIDs) const
00214 {
00215 cellLIDs.resize(0);
00216 int nc = numCells(cellDim);
00217
00218 for (int c=0; c<nc; c++)
00219 {
00220 int lc = label(cellDim, c);
00221 if (lc==labelToCheck) cellLIDs.append(c);
00222 }
00223 }
00224
00225 Set<int> MeshBase::getAllLabelsForDimension(int cellDim) const
00226 {
00227 int nc = numCells(cellDim);
00228 Set<int> rtn;
00229
00230 for (int c=0; c<nc; c++)
00231 {
00232 rtn.put(label(cellDim, c));
00233 }
00234 return rtn;
00235 }
00236
00237
00238
00239 bool MeshBase::hasSpecialWeight(int dim, int cellLID) const {
00240 if (specialWeights_[dim-1].containsKey(cellLID))
00241 return ((specialWeights_[dim-1].get(cellLID).size() > 0));
00242 else
00243 return false;
00244 }
00245
00246 void MeshBase::setSpecialWeight(int dim, int cellLID, Array<double>& w) const {
00247 specialWeights_[dim-1].put(cellLID,w);
00248 }
00249
00250 void MeshBase::getSpecialWeight(int dim, int cellLID, Array<double>& w) const {
00251 w = specialWeights_[dim-1].get(cellLID);
00252 }
00253
00254
00255 void MeshBase::flushSpecialWeights() const {
00256
00257 for (int d = 0 ; d < dim_ ; d++){
00258
00259 specialWeights_[d] = Sundance::Map< int , Array<double> >();
00260 }
00261 validWeights_ = true;
00262 }
00263
00264
00265
00266 void MeshBase::flushCurvePoints() const {
00267
00268
00269 curveID_to_ArrayIndex_ = Sundance::Map< int , int >();
00270 nrCurvesForIntegral_ = 0;
00271 curvePoints_Are_Valid_ = true;
00272 for (int c = 0 ; c < curvePoints_.size() ; c++ ){
00273
00274 curvePoints_[c] = Sundance::Map< int , Array<Point> >();
00275 curveDerivative_[c] = Sundance::Map< int , Array<Point> >();
00276 curveNormal_[c] = Sundance::Map< int , Array<Point> >();
00277 }
00278 }
00279
00280 bool MeshBase::hasCurvePoints(int maxCellLID , int curveID) const {
00281 if (curvePoints_[mapCurveID_to_Index(curveID)].containsKey(maxCellLID))
00282 return ( curvePoints_[mapCurveID_to_Index(curveID)].get(maxCellLID).size() > 0 );
00283 else
00284 return false;
00285 }
00286
00287 void MeshBase::setCurvePoints(int maxCellLID, int curveID ,
00288 Array<Point>& points , Array<Point>& derivs , Array<Point>& normals) const {
00289
00290 Tabs tabs;
00291 int verbo = 0;
00292 SUNDANCE_MSG3(verbo, tabs << "MeshBase::setCurvePoints , nr:" << nrCurvesForIntegral_);
00293 curvePoints_[mapCurveID_to_Index(curveID)].put( maxCellLID , points );
00294 curveDerivative_[mapCurveID_to_Index(curveID)].put( maxCellLID , derivs );
00295 curveNormal_[mapCurveID_to_Index(curveID)].put( maxCellLID , normals );
00296
00297 }
00298
00299 void MeshBase::getCurvePoints(int maxCellLID, int curveID ,
00300 Array<Point>& points , Array<Point>& derivs , Array<Point>& normals) const {
00301
00302 Tabs tabs;
00303 int verbo = 0;
00304 SUNDANCE_MSG3(verbo, tabs << "MeshBase::getCurvePoints , nr:" << nrCurvesForIntegral_);
00305 points = curvePoints_[mapCurveID_to_Index(curveID)].get( maxCellLID );
00306 derivs = curveDerivative_[mapCurveID_to_Index(curveID)].get( maxCellLID );
00307 normals = curveNormal_[mapCurveID_to_Index(curveID)].get( maxCellLID );
00308
00309 }
00310
00311 int MeshBase::mapCurveID_to_Index(int curveID) const {
00312
00313 Tabs tabs;
00314 int verbo = 0;
00315
00316 SUNDANCE_MSG3(verbo, tabs << "MeshBase::mapCurveID_to_Index curveID:" << curveID);
00317 if (curveID_to_ArrayIndex_.containsKey(curveID)){
00318 SUNDANCE_MSG3(verbo, tabs << "MeshBase::mapCurveID_to_Index value found for curveID:" << curveID << " ret:" << curveID_to_ArrayIndex_.get(curveID));
00319 return curveID_to_ArrayIndex_.get(curveID);
00320 } else {
00321 SUNDANCE_MSG3(verbo, tabs << "MeshBase::mapCurveID_to_Index create new :" << nrCurvesForIntegral_);
00322 curveID_to_ArrayIndex_.put( curveID , nrCurvesForIntegral_ );
00323 SUNDANCE_MSG3(verbo, tabs << "MeshBase::mapCurveID_to_Index , increment ");
00324 nrCurvesForIntegral_++;
00325 curvePoints_.resize(nrCurvesForIntegral_);
00326 curveDerivative_.resize(nrCurvesForIntegral_);
00327 curveNormal_.resize(nrCurvesForIntegral_);
00328 SUNDANCE_MSG3(verbo, tabs << "MeshBase::mapCurveID_to_Index create new :" << nrCurvesForIntegral_);
00329 return nrCurvesForIntegral_-1;
00330 }
00331
00332 }