SundancePeriodicMesh1D.cpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 //
00004 //                              Sundance
00005 //                 Copyright (2005) Sandia Corporation
00006 //
00007 // Copyright (year first published) Sandia Corporation.  Under the terms
00008 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
00009 // retains certain rights in this software.
00010 //
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA
00025 // Questions? Contact Kevin Long (krlong@sandia.gov),
00026 // Sandia National Laboratories, Livermore, California, USA
00027 //
00028 // ************************************************************************
00029 /* @HEADER@ */
00030 
00031 #include "SundancePeriodicMesh1D.hpp"
00032 
00033 #include "SundanceCellJacobianBatch.hpp"
00034 #include "SundanceMaximalCofacetBatch.hpp"
00035 #include "SundanceDebug.hpp"
00036 #include "SundanceOut.hpp"
00037 #include "Teuchos_MPIContainerComm.hpp"
00038 #include "Teuchos_Time.hpp"
00039 #include "Teuchos_TimeMonitor.hpp"
00040 #include "SundanceObjectWithVerbosity.hpp"
00041 
00042 using namespace Sundance;
00043 using namespace Teuchos;
00044 using namespace std;
00045 
00046 
00047 PeriodicMesh1D::PeriodicMesh1D(double xMin, double xMax, int numElems)
00048   : MeshBase(1, MPIComm::self(), ExodusMeshOrder),
00049     numElems_(numElems),
00050     xMin_(xMin),
00051     xMax_(xMax),
00052     x_(numElems+1),
00053     verts_(numElems),
00054     labels_(2)
00055 {
00056   labels_[0].resize(numElems_);
00057   labels_[1].resize(numElems_);
00058 
00059   for (int i=0; i<numElems_; i++)
00060   {
00061     labels_[0][i] = 0;
00062     labels_[1][i] = 1;
00063     verts_[i].resize(2);
00064     verts_[i][0] = i;
00065     verts_[i][1] = (i+1) % numElems;
00066   }
00067 
00068   for (int i=0; i<=numElems_; i++)
00069   {
00070     x_[i] = Point(xMin_ + ((double) i)/((double) numElems_)*(xMax_-xMin_));
00071   }
00072 }
00073 
00074 int PeriodicMesh1D::numCells(int cellDim) const
00075 {
00076   switch(cellDim)
00077   {
00078     case 0 :
00079       return numElems_;
00080     case 1:
00081       return numElems_;
00082     default:
00083       TEST_FOR_EXCEPT(true);
00084   }
00085   return -1; // -Wall
00086 }
00087 
00088 
00089 Point PeriodicMesh1D::nodePosition(int i) const 
00090 {
00091   return x_[i];
00092 }
00093 
00094 
00095 const double* PeriodicMesh1D::nodePositionView(int i) const 
00096 {
00097   return &(x_[i][0]);
00098 }
00099 
00100 void PeriodicMesh1D::getJacobians(int cellDim, const Array<int>& cellLID,
00101     CellJacobianBatch& jBatch) const
00102 {
00103   TEST_FOR_EXCEPTION(cellDim < 0 || cellDim > spatialDim(), InternalError,
00104     "cellDim=" << cellDim 
00105     << " is not in expected range [0, " << spatialDim()
00106     << "]");
00107 
00108   jBatch.resize(cellLID.size(), spatialDim(), cellDim);
00109 
00110   int nCells = cellLID.size();
00111 
00112   if (cellDim==0)
00113   {
00114     for (int i=0; i<nCells; i++)
00115     {
00116       double* detJ = jBatch.detJ(i);
00117       *detJ = 1.0;
00118     }
00119   }
00120   else
00121   {
00122     for (int i=0; i<nCells; i++)
00123     {
00124       int lid = cellLID[i];
00125       double* J = jBatch.jVals(i);
00126       double x0 = x_[lid][0];
00127       double x1 = x_[lid+1][0];
00128       J[0] = fabs(x1-x0);
00129     }
00130   }
00131 }
00132 
00133 
00134 void PeriodicMesh1D::getCellDiameters(int cellDim, const Array<int>& cellLID,
00135   Array<double>& cellDiameters) const
00136 {
00137   cellDiameters.resize(cellLID.size());
00138   
00139   TEST_FOR_EXCEPT(cellDim < 0 || cellDim > 1);
00140 
00141   if (cellDim==1)
00142   {
00143     for (int i=0; i<cellLID.size(); i++)
00144     {
00145       int c = cellLID[i];
00146       double h = x_[c+1][0]-x_[c][0];
00147       cellDiameters[i] = h;
00148     }
00149   }
00150   else
00151   {
00152     for (int i=0; i<cellLID.size(); i++)
00153     {
00154       cellDiameters[i] = 1.0;
00155     }
00156   }
00157 }
00158 
00159 void PeriodicMesh1D::pushForward(int cellDim, const Array<int>& cellLID,
00160     const Array<Point>& refQuadPts,
00161     Array<Point>& physQuadPts) const
00162 {
00163   TEST_FOR_EXCEPT(cellDim < 0 || cellDim > 1);
00164 
00165   if (cellDim==1)
00166   {
00167     if (physQuadPts.size() > 0) physQuadPts.resize(0);
00168     physQuadPts.reserve(refQuadPts.size() * cellLID.size());
00169     
00170     for (int i=0; i<cellLID.size(); i++)
00171     {
00172       int c = cellLID[i];
00173       Point h = x_[c+1]-x_[c];
00174       for (int q=0; q<refQuadPts.size(); q++)
00175       {
00176         physQuadPts.append(Point(x_[c] + refQuadPts[q][0] * h));
00177       }
00178     }
00179   }
00180   else
00181   {
00182     for (int i=0; i<cellLID.size(); i++)
00183     {
00184       physQuadPts.append(x_[cellLID[i]]);
00185     }
00186   }
00187 }
00188 
00189 int PeriodicMesh1D::numFacets(int cellDim, int cellLID,
00190     int facetDim) const
00191 {
00192   TEST_FOR_EXCEPT(cellLID < 0 || cellLID >= numElems_);
00193   if (cellDim == 1 && facetDim==0) return 2;
00194   return 0;
00195 }
00196 
00197 
00198     
00199 int PeriodicMesh1D::facetLID(int cellDim, int cellLID,
00200   int facetDim, int facetIndex,
00201   int& facetOrientation) const
00202 {
00203   TEST_FOR_EXCEPT(cellLID < 0 || cellLID >= numElems_);
00204 
00205   TEST_FOR_EXCEPT(cellDim != 1);
00206   TEST_FOR_EXCEPT(facetDim != 0);
00207   TEST_FOR_EXCEPT(facetIndex < 0);
00208   TEST_FOR_EXCEPT(facetIndex > 1);
00209 
00210   return verts_[cellLID][facetIndex];
00211 }
00212 
00213 void PeriodicMesh1D::getFacetLIDs(int cellDim,
00214     const Array<int>& cellLID,
00215     int facetDim,
00216     Array<int>& facetLID,
00217     Array<int>& facetSign) const
00218 {
00219   facetLID.resize(2*cellLID.size());
00220   facetSign.resize(2*cellLID.size());
00221 
00222   for (int i=0; i<cellLID.size(); i++) 
00223   {
00224     facetLID[2*i] = this->facetLID(cellDim, cellLID[i], facetDim, 0, facetSign[2*i]);
00225     facetLID[2*i+1] = this->facetLID(cellDim, cellLID[i], facetDim, 1, facetSign[2*i]);
00226   }
00227 }
00228 
00229 
00230 const int* PeriodicMesh1D::elemZeroFacetView(int cellLID) const
00231 {
00232   return &(verts_[cellLID][0]);
00233 }
00234 
00235 
00236 int PeriodicMesh1D::numMaxCofacets(int cellDim, int cellLID) const
00237 {
00238   TEST_FOR_EXCEPT(cellDim != 0);
00239   return 2;
00240 }
00241 
00242 int PeriodicMesh1D::maxCofacetLID(int cellDim, int cellLID,
00243     int cofacetIndex,
00244     int& facetIndex) const
00245 {
00246   TEST_FOR_EXCEPT(cellDim != 0);
00247   if (cofacetIndex==0) return (cellLID-1) % numElems_;
00248   return cellLID;
00249 }
00250 
00251 void PeriodicMesh1D::getMaxCofacetLIDs(const Array<int>& cellLIDs,
00252     MaximalCofacetBatch& cofacets) const
00253 {
00254   TEST_FOR_EXCEPT(true);
00255 }
00256 
00257 void PeriodicMesh1D::getCofacets(int cellDim, int cellLID,
00258     int cofacetDim, Array<int>& cofacetLIDs) const
00259 {
00260   TEST_FOR_EXCEPT(cellDim != 0);
00261   TEST_FOR_EXCEPT(cofacetDim != 1);
00262 
00263   cofacetLIDs.resize(2);
00264   cofacetLIDs[0] = (cellLID-1) % numElems_;
00265   cofacetLIDs[1] = cellLID;
00266 }
00267 
00268 int PeriodicMesh1D::mapGIDToLID(int cellDim, int globalIndex) const
00269 {
00270   return globalIndex;
00271 }
00272 
00273 bool PeriodicMesh1D::hasGID(int cellDim, int globalIndex) const
00274 {
00275   return true;
00276 }
00277 
00278 int PeriodicMesh1D::mapLIDToGID(int cellDim, int localIndex) const
00279 {
00280   return localIndex;
00281 }
00282 
00283 CellType PeriodicMesh1D::cellType(int cellDim) const
00284 {
00285   if (cellDim==0) return PointCell;
00286   else if (cellDim==1) return LineCell;
00287   else return NullCell;
00288 }
00289 
00290 int PeriodicMesh1D::label(int cellDim, int cellLID) const
00291 {
00292   return labels_[cellDim][cellLID];
00293 }
00294 
00295 void PeriodicMesh1D::getLabels(int cellDim, const Array<int>& cellLID,
00296   Array<int>& labels) const
00297 {
00298   labels.resize(cellLID.size());
00299   const Array<int>& ld = labels_[cellDim];
00300   for (int i=0; i<cellLID.size(); i++)
00301   {
00302     labels[i] = ld[cellLID[i]];
00303   }
00304 }
00305 
00306 Set<int> PeriodicMesh1D::getAllLabelsForDimension(int cellDim) const
00307 {
00308   Set<int> rtn;
00309 
00310   const Array<int>& ld = labels_[cellDim];
00311   for (int i=0; i<ld.size(); i++)
00312   {
00313     rtn.put(ld[i]);
00314   }
00315   
00316   return rtn;
00317 }
00318 
00319 void PeriodicMesh1D::setLabel(int cellDim, int cellLID, int label)
00320 {
00321   labels_[cellDim][cellLID] = label;
00322 }
00323 
00324 
00325 void PeriodicMesh1D::getLIDsForLabel(int cellDim, int label, Array<int>& cellLIDs) const
00326 {
00327   cellLIDs.resize(0);
00328   const Array<int>& ld = labels_[cellDim];
00329   for (int i=0; i<ld.size(); i++)
00330   {
00331     if (ld[i] == label) cellLIDs.append(i);
00332   }
00333 }

Site Contact