SundancePeriodicSingleCellMesh1D.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 "SundancePeriodicSingleCellMesh1D.hpp"
00032 
00033 #include "SundanceCellJacobianBatch.hpp"
00034 #include "SundanceMaximalCofacetBatch.hpp"
00035 #include "SundanceDebug.hpp"
00036 #include "SundanceOut.hpp"
00037 #include "PlayaMPIContainerComm.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 using Playa::MPIComm;
00046 using Playa::MPIContainerComm;
00047 
00048 
00049 PeriodicSingleCellMesh1D::PeriodicSingleCellMesh1D(double xMin, double xMax)
00050   : MeshBase(1, MPIComm::self(), ExodusMeshOrder),
00051     xMin_(xMin),
00052     xMax_(xMax),
00053     vert_(0),
00054     labels_(2)
00055 {
00056   labels_[0] = 0;
00057   labels_[1] = 0;
00058 }
00059 
00060 int PeriodicSingleCellMesh1D::numCells(int cellDim) const
00061 {
00062   switch(cellDim)
00063   {
00064     case 0 :
00065       return 1;
00066     case 1:
00067       return 1;
00068     default:
00069       TEUCHOS_TEST_FOR_EXCEPT(true);
00070   }
00071   return -1; // -Wall
00072 }
00073 
00074 
00075 Point PeriodicSingleCellMesh1D::nodePosition(int i) const 
00076 {
00077   TEUCHOS_TEST_FOR_EXCEPT(i != 0);
00078   return xMin_;
00079 }
00080 
00081 
00082 const double* PeriodicSingleCellMesh1D::nodePositionView(int i) const 
00083 {
00084   TEUCHOS_TEST_FOR_EXCEPT(i != 0);
00085   return &(xMin_);
00086 }
00087 
00088 void PeriodicSingleCellMesh1D::getJacobians(int cellDim, const Array<int>& cellLID,
00089     CellJacobianBatch& jBatch) const
00090 {
00091   TEUCHOS_TEST_FOR_EXCEPTION(cellDim < 0 || cellDim > spatialDim(), std::logic_error,
00092     "cellDim=" << cellDim 
00093     << " is not in expected range [0, " << spatialDim()
00094     << "]");
00095 
00096   jBatch.resize(cellLID.size(), spatialDim(), cellDim);
00097 
00098   int nCells = cellLID.size();
00099 
00100   TEUCHOS_TEST_FOR_EXCEPT(nCells != 1);
00101 
00102   if (cellDim==0)
00103   {
00104     for (int i=0; i<nCells; i++)
00105     {
00106       double* detJ = jBatch.detJ(i);
00107       *detJ = 1.0;
00108     }
00109   }
00110   else
00111   {
00112     for (int i=0; i<nCells; i++)
00113     {
00114       double* J = jBatch.jVals(i);
00115       J[0] = fabs(xMin_-xMax_);
00116     }
00117   }
00118 }
00119 
00120 
00121 void PeriodicSingleCellMesh1D::getCellDiameters(int cellDim, const Array<int>& cellLID,
00122   Array<double>& cellDiameters) const
00123 {
00124   cellDiameters.resize(1);
00125   
00126   TEUCHOS_TEST_FOR_EXCEPT(cellDim != 1);
00127 
00128   cellDiameters[0] = ::fabs(xMax_-xMin_);
00129 }
00130 
00131 void PeriodicSingleCellMesh1D::pushForward(int cellDim, const Array<int>& cellLID,
00132     const Array<Point>& refQuadPts,
00133     Array<Point>& physQuadPts) const
00134 {
00135   TEUCHOS_TEST_FOR_EXCEPT(cellDim < 0 || cellDim > 1);
00136 
00137   TEUCHOS_TEST_FOR_EXCEPT(cellLID.size() > 1);
00138 
00139   if (cellDim==1)
00140   {
00141     if (physQuadPts.size() > 0) physQuadPts.resize(0);
00142     physQuadPts.reserve(refQuadPts.size() * cellLID.size());
00143     
00144     for (int i=0; i<cellLID.size(); i++)
00145     {
00146       double h = xMax_ - xMin_;
00147       for (int q=0; q<refQuadPts.size(); q++)
00148       {
00149         physQuadPts.append(xMin_ + refQuadPts[q][0] * h);
00150       }
00151     }
00152   }
00153   else
00154   {
00155     for (int i=0; i<cellLID.size(); i++)
00156     {
00157       physQuadPts.append(xMin_);
00158     }
00159   }
00160 }
00161 
00162 int PeriodicSingleCellMesh1D::numFacets(int cellDim, int cellLID,
00163     int facetDim) const
00164 {
00165   TEUCHOS_TEST_FOR_EXCEPT(cellLID != 0);
00166   if (cellDim == 1 && facetDim==0) return 1;
00167   return 0;
00168 }
00169 
00170 
00171     
00172 int PeriodicSingleCellMesh1D::facetLID(int cellDim, int cellLID,
00173   int facetDim, int facetIndex,
00174   int& facetOrientation) const
00175 {
00176   TEUCHOS_TEST_FOR_EXCEPT(cellLID < 0 || cellLID >= 1);
00177 
00178   TEUCHOS_TEST_FOR_EXCEPT(cellDim != 1);
00179   TEUCHOS_TEST_FOR_EXCEPT(facetDim != 0);
00180   TEUCHOS_TEST_FOR_EXCEPT(facetIndex < 0);
00181   TEUCHOS_TEST_FOR_EXCEPT(facetIndex > 1);
00182 
00183   return vert_;
00184 }
00185 
00186 void PeriodicSingleCellMesh1D::getFacetLIDs(int cellDim,
00187     const Array<int>& cellLID,
00188     int facetDim,
00189     Array<int>& facetLID,
00190     Array<int>& facetSign) const
00191 {
00192   facetLID.resize(2*cellLID.size());
00193   facetSign.resize(2*cellLID.size());
00194 
00195   for (int i=0; i<cellLID.size(); i++) 
00196   {
00197     facetLID[2*i] = this->facetLID(cellDim, cellLID[i], facetDim, 0, facetSign[2*i]);
00198     facetLID[2*i+1] = this->facetLID(cellDim, cellLID[i], facetDim, 1, facetSign[2*i]);
00199   }
00200 }
00201 
00202 
00203 const int* PeriodicSingleCellMesh1D::elemZeroFacetView(int cellLID) const
00204 {
00205   TEUCHOS_TEST_FOR_EXCEPT(cellLID != 0);
00206   return &vert_;
00207 }
00208 
00209 
00210 int PeriodicSingleCellMesh1D::numMaxCofacets(int cellDim, int cellLID) const
00211 {
00212   TEUCHOS_TEST_FOR_EXCEPT(cellDim != 0);
00213   return 1;
00214 }
00215 
00216 int PeriodicSingleCellMesh1D::maxCofacetLID(int cellDim, int cellLID,
00217     int cofacetIndex,
00218     int& facetIndex) const
00219 {
00220   TEUCHOS_TEST_FOR_EXCEPT(cellDim != 0 || cellLID != 0);
00221   facetIndex = 0;
00222   return 0;
00223 }
00224 
00225 void PeriodicSingleCellMesh1D::getMaxCofacetLIDs(const Array<int>& cellLIDs,
00226     MaximalCofacetBatch& cofacets) const
00227 {
00228   TEUCHOS_TEST_FOR_EXCEPT(true);
00229 }
00230 
00231 void PeriodicSingleCellMesh1D::getCofacets(int cellDim, int cellLID,
00232     int cofacetDim, Array<int>& cofacetLIDs) const
00233 {
00234   TEUCHOS_TEST_FOR_EXCEPT(cellDim != 0);
00235   TEUCHOS_TEST_FOR_EXCEPT(cofacetDim != 1);
00236 
00237   cofacetLIDs.resize(1);
00238   cofacetLIDs[0] = 0;
00239 }
00240 
00241 int PeriodicSingleCellMesh1D::mapGIDToLID(int cellDim, int globalIndex) const
00242 {
00243   return globalIndex;
00244 }
00245 
00246 bool PeriodicSingleCellMesh1D::hasGID(int cellDim, int globalIndex) const
00247 {
00248   return globalIndex==0;
00249 }
00250 
00251 int PeriodicSingleCellMesh1D::mapLIDToGID(int cellDim, int localIndex) const
00252 {
00253   return localIndex;
00254 }
00255 
00256 CellType PeriodicSingleCellMesh1D::cellType(int cellDim) const
00257 {
00258   if (cellDim==0) return PointCell;
00259   else if (cellDim==1) return LineCell;
00260   else return NullCell;
00261 }
00262 
00263 int PeriodicSingleCellMesh1D::label(int cellDim, int cellLID) const
00264 {
00265   return labels_[cellDim];
00266 }
00267 
00268 void PeriodicSingleCellMesh1D::getLabels(int cellDim, const Array<int>& cellLID,
00269   Array<int>& labels) const
00270 {
00271   labels.resize(cellLID.size());
00272   for (int i=0; i<cellLID.size(); i++)
00273   {
00274     labels[i] = labels_[cellDim];
00275   }
00276 }
00277 
00278 Set<int> PeriodicSingleCellMesh1D::getAllLabelsForDimension(int cellDim) const
00279 {
00280   Set<int> rtn;
00281 
00282   rtn.put(labels_[cellDim]);
00283     
00284   return rtn;
00285 }
00286 
00287 void PeriodicSingleCellMesh1D::setLabel(int cellDim, int cellLID, int label)
00288 {
00289   labels_[cellDim] = label;
00290 }
00291 
00292 
00293 void PeriodicSingleCellMesh1D::getLIDsForLabel(int cellDim, int label, Array<int>& cellLIDs) const
00294 {
00295   cellLIDs.resize(0);
00296   if (label != labels_[cellDim]) cellLIDs.append(0);
00297 }

Site Contact