SundancePeriodicSingleCellMesh1D.cpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                             Sundance
00005 //                 Copyright 2011 Sandia Corporation
00006 // 
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Kevin Long (kevin.long@ttu.edu)
00038 // 
00039 
00040 /* @HEADER@ */
00041 
00042 #include "SundancePeriodicSingleCellMesh1D.hpp"
00043 
00044 #include "SundanceCellJacobianBatch.hpp"
00045 #include "SundanceMaximalCofacetBatch.hpp"
00046 #include "SundanceDebug.hpp"
00047 #include "SundanceOut.hpp"
00048 #include "PlayaMPIContainerComm.hpp"
00049 #include "Teuchos_Time.hpp"
00050 #include "Teuchos_TimeMonitor.hpp"
00051 #include "SundanceObjectWithVerbosity.hpp"
00052 
00053 using namespace Sundance;
00054 using namespace Teuchos;
00055 using namespace std;
00056 using Playa::MPIComm;
00057 using Playa::MPIContainerComm;
00058 
00059 
00060 PeriodicSingleCellMesh1D::PeriodicSingleCellMesh1D(double xMin, double xMax)
00061   : MeshBase(1, MPIComm::self(), ExodusMeshOrder),
00062     xMin_(xMin),
00063     xMax_(xMax),
00064     vert_(0),
00065     labels_(2)
00066 {
00067   labels_[0] = 0;
00068   labels_[1] = 0;
00069 }
00070 
00071 int PeriodicSingleCellMesh1D::numCells(int cellDim) const
00072 {
00073   switch(cellDim)
00074   {
00075     case 0 :
00076       return 1;
00077     case 1:
00078       return 1;
00079     default:
00080       TEUCHOS_TEST_FOR_EXCEPT(true);
00081   }
00082   return -1; // -Wall
00083 }
00084 
00085 
00086 Point PeriodicSingleCellMesh1D::nodePosition(int i) const 
00087 {
00088   TEUCHOS_TEST_FOR_EXCEPT(i != 0);
00089   return xMin_;
00090 }
00091 
00092 
00093 const double* PeriodicSingleCellMesh1D::nodePositionView(int i) const 
00094 {
00095   TEUCHOS_TEST_FOR_EXCEPT(i != 0);
00096   return &(xMin_);
00097 }
00098 
00099 void PeriodicSingleCellMesh1D::getJacobians(int cellDim, const Array<int>& cellLID,
00100     CellJacobianBatch& jBatch) const
00101 {
00102   TEUCHOS_TEST_FOR_EXCEPTION(cellDim < 0 || cellDim > spatialDim(), std::logic_error,
00103     "cellDim=" << cellDim 
00104     << " is not in expected range [0, " << spatialDim()
00105     << "]");
00106 
00107   jBatch.resize(cellLID.size(), spatialDim(), cellDim);
00108 
00109   int nCells = cellLID.size();
00110 
00111   TEUCHOS_TEST_FOR_EXCEPT(nCells != 1);
00112 
00113   if (cellDim==0)
00114   {
00115     for (int i=0; i<nCells; i++)
00116     {
00117       double* detJ = jBatch.detJ(i);
00118       *detJ = 1.0;
00119     }
00120   }
00121   else
00122   {
00123     for (int i=0; i<nCells; i++)
00124     {
00125       double* J = jBatch.jVals(i);
00126       J[0] = fabs(xMin_-xMax_);
00127     }
00128   }
00129 }
00130 
00131 
00132 void PeriodicSingleCellMesh1D::getCellDiameters(int cellDim, const Array<int>& cellLID,
00133   Array<double>& cellDiameters) const
00134 {
00135   cellDiameters.resize(1);
00136   
00137   TEUCHOS_TEST_FOR_EXCEPT(cellDim != 1);
00138 
00139   cellDiameters[0] = ::fabs(xMax_-xMin_);
00140 }
00141 
00142 void PeriodicSingleCellMesh1D::pushForward(int cellDim, const Array<int>& cellLID,
00143     const Array<Point>& refQuadPts,
00144     Array<Point>& physQuadPts) const
00145 {
00146   TEUCHOS_TEST_FOR_EXCEPT(cellDim < 0 || cellDim > 1);
00147 
00148   TEUCHOS_TEST_FOR_EXCEPT(cellLID.size() > 1);
00149 
00150   if (cellDim==1)
00151   {
00152     if (physQuadPts.size() > 0) physQuadPts.resize(0);
00153     physQuadPts.reserve(refQuadPts.size() * cellLID.size());
00154     
00155     for (int i=0; i<cellLID.size(); i++)
00156     {
00157       double h = xMax_ - xMin_;
00158       for (int q=0; q<refQuadPts.size(); q++)
00159       {
00160         physQuadPts.append(xMin_ + refQuadPts[q][0] * h);
00161       }
00162     }
00163   }
00164   else
00165   {
00166     for (int i=0; i<cellLID.size(); i++)
00167     {
00168       physQuadPts.append(xMin_);
00169     }
00170   }
00171 }
00172 
00173 int PeriodicSingleCellMesh1D::numFacets(int cellDim, int cellLID,
00174     int facetDim) const
00175 {
00176   TEUCHOS_TEST_FOR_EXCEPT(cellLID != 0);
00177   if (cellDim == 1 && facetDim==0) return 1;
00178   return 0;
00179 }
00180 
00181 
00182     
00183 int PeriodicSingleCellMesh1D::facetLID(int cellDim, int cellLID,
00184   int facetDim, int facetIndex,
00185   int& facetOrientation) const
00186 {
00187   TEUCHOS_TEST_FOR_EXCEPT(cellLID < 0 || cellLID >= 1);
00188 
00189   TEUCHOS_TEST_FOR_EXCEPT(cellDim != 1);
00190   TEUCHOS_TEST_FOR_EXCEPT(facetDim != 0);
00191   TEUCHOS_TEST_FOR_EXCEPT(facetIndex < 0);
00192   TEUCHOS_TEST_FOR_EXCEPT(facetIndex > 1);
00193 
00194   return vert_;
00195 }
00196 
00197 void PeriodicSingleCellMesh1D::getFacetLIDs(int cellDim,
00198     const Array<int>& cellLID,
00199     int facetDim,
00200     Array<int>& facetLID,
00201     Array<int>& facetSign) const
00202 {
00203   facetLID.resize(2*cellLID.size());
00204   facetSign.resize(2*cellLID.size());
00205 
00206   for (int i=0; i<cellLID.size(); i++) 
00207   {
00208     facetLID[2*i] = this->facetLID(cellDim, cellLID[i], facetDim, 0, facetSign[2*i]);
00209     facetLID[2*i+1] = this->facetLID(cellDim, cellLID[i], facetDim, 1, facetSign[2*i]);
00210   }
00211 }
00212 
00213 
00214 const int* PeriodicSingleCellMesh1D::elemZeroFacetView(int cellLID) const
00215 {
00216   TEUCHOS_TEST_FOR_EXCEPT(cellLID != 0);
00217   return &vert_;
00218 }
00219 
00220 
00221 int PeriodicSingleCellMesh1D::numMaxCofacets(int cellDim, int cellLID) const
00222 {
00223   TEUCHOS_TEST_FOR_EXCEPT(cellDim != 0);
00224   return 1;
00225 }
00226 
00227 int PeriodicSingleCellMesh1D::maxCofacetLID(int cellDim, int cellLID,
00228     int cofacetIndex,
00229     int& facetIndex) const
00230 {
00231   TEUCHOS_TEST_FOR_EXCEPT(cellDim != 0 || cellLID != 0);
00232   facetIndex = 0;
00233   return 0;
00234 }
00235 
00236 void PeriodicSingleCellMesh1D::getMaxCofacetLIDs(const Array<int>& cellLIDs,
00237     MaximalCofacetBatch& cofacets) const
00238 {
00239   TEUCHOS_TEST_FOR_EXCEPT(true);
00240 }
00241 
00242 void PeriodicSingleCellMesh1D::getCofacets(int cellDim, int cellLID,
00243     int cofacetDim, Array<int>& cofacetLIDs) const
00244 {
00245   TEUCHOS_TEST_FOR_EXCEPT(cellDim != 0);
00246   TEUCHOS_TEST_FOR_EXCEPT(cofacetDim != 1);
00247 
00248   cofacetLIDs.resize(1);
00249   cofacetLIDs[0] = 0;
00250 }
00251 
00252 int PeriodicSingleCellMesh1D::mapGIDToLID(int cellDim, int globalIndex) const
00253 {
00254   return globalIndex;
00255 }
00256 
00257 bool PeriodicSingleCellMesh1D::hasGID(int cellDim, int globalIndex) const
00258 {
00259   return globalIndex==0;
00260 }
00261 
00262 int PeriodicSingleCellMesh1D::mapLIDToGID(int cellDim, int localIndex) const
00263 {
00264   return localIndex;
00265 }
00266 
00267 CellType PeriodicSingleCellMesh1D::cellType(int cellDim) const
00268 {
00269   if (cellDim==0) return PointCell;
00270   else if (cellDim==1) return LineCell;
00271   else return NullCell;
00272 }
00273 
00274 int PeriodicSingleCellMesh1D::label(int cellDim, int cellLID) const
00275 {
00276   return labels_[cellDim];
00277 }
00278 
00279 void PeriodicSingleCellMesh1D::getLabels(int cellDim, const Array<int>& cellLID,
00280   Array<int>& labels) const
00281 {
00282   labels.resize(cellLID.size());
00283   for (int i=0; i<cellLID.size(); i++)
00284   {
00285     labels[i] = labels_[cellDim];
00286   }
00287 }
00288 
00289 Set<int> PeriodicSingleCellMesh1D::getAllLabelsForDimension(int cellDim) const
00290 {
00291   Set<int> rtn;
00292 
00293   rtn.put(labels_[cellDim]);
00294     
00295   return rtn;
00296 }
00297 
00298 void PeriodicSingleCellMesh1D::setLabel(int cellDim, int cellLID, int label)
00299 {
00300   labels_[cellDim] = label;
00301 }
00302 
00303 
00304 void PeriodicSingleCellMesh1D::getLIDsForLabel(int cellDim, int label, Array<int>& cellLIDs) const
00305 {
00306   cellLIDs.resize(0);
00307   if (label != labels_[cellDim]) cellLIDs.append(0);
00308 }

Site Contact